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

React.lazy and navi #140

Open
DB-Alex opened this issue Sep 26, 2019 · 2 comments
Open

React.lazy and navi #140

DB-Alex opened this issue Sep 26, 2019 · 2 comments

Comments

@DB-Alex
Copy link

DB-Alex commented Sep 26, 2019

Is it already possible to lazy load components using navi?

import React, {lazy} from 'react';
import useStyles from './Blocks.styles';

const Paragraph = lazy(() => import('components/Paragraph'));
{blocks.map((block, index) => {
                if (block.blockName === 'core/paragraph') {
                    return (
                        <Paragraph
                            key={index}
                            content={block.innerContent[0]}
                        />
                    );
                } else {
                    return null;
                }
            })}

This now throws:

{ Invariant Violation: ReactDOMServer does not yet support lazy-loaded components.

Is there another way to archive this with navi?

@jamesknelson
Copy link
Collaborator

There's no way to do it with React.lazy (yet), but it's possible to load components/routes asynchronously within your routes, and pass them to your component as view props.

E.g. using Navi's lazy function:

import { lazy, mount } from 'navi'

export default mount({
  '/': lazy(() => import('./landingRoutes')),
  '/blog': lazy(() => import('./blogRoutes')),
})

@tony
Copy link
Contributor

tony commented Feb 10, 2020

@jamesknelson Does lazy loading a route imply webpack will chunk it?

Is there a minimal viable example of webpack, typescript, react-navi with automatic chunking by chance?

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

No branches or pull requests

3 participants