Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rethink use of Loadable component #12

Open
csantiago132 opened this issue Oct 31, 2018 · 4 comments
Open

rethink use of Loadable component #12

csantiago132 opened this issue Oct 31, 2018 · 4 comments

Comments

@csantiago132
Copy link
Owner

types are being lost due to how React-Loadable imports components

@csantiago132
Copy link
Owner Author

based on this bloc post and react's release notes on 16.6

// new way in react 16.6
import React, { lazy, Suspense } from 'react';
import LoadingIndicator from './components/LoadingIndicator';

/**
 * set component by importing it like Loadable
 */
const Component = lazy(() => import('./ComponentExample'));

export default () => (
  /**
   * Fallback is the Loading component; spinner or whatever we want to pass
   * 
   * Suspense is the wrapper used to container everything exported
   * 
   * Pass the component wrapped in lazy() as a children of <Suspense/>
   * 
   */
  <Suspense fallback={<LoadingIndicator />}>
    <Component />
  </Suspense>
);
// react-loadable reference
import Loadable from 'react-loadable';

export default Loadable({
  loader: () => import('./CreateChatRoom'),
  loading: () => null,
});

@csantiago132
Copy link
Owner Author

@types/react has not been updated to v16.6, currently its at v16.4.14 yet so imports in typescript from { lazy, Suspense } will error out since they're not define.

@csantiago132
Copy link
Owner Author

see this issue tracking it

@csantiago132
Copy link
Owner Author

another workaround: seems like @types/16.6 will take a while to get out, looking at 16.7 too

import React from "react";
const Suspense = (React as any).Suspense;
const lazy = (React as any).lazy;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant