Created
April 5, 2021 03:17
-
-
Save ChaseH88/df7194c961f5536792edc9e78dbf28f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { FC, lazy, Suspense, useState } from 'react'; | |
| // Code Spliting with dynamic imports | |
| const MenuContainer = lazy(() => | |
| import('./MenuContainer') | |
| .then(({ MenuContainer }) => ({ default: MenuContainer })), | |
| ); | |
| const Navigation: FC = (): JSX.Element => { | |
| const [open, toggle] = useState<boolean>(false); | |
| return ( | |
| <> | |
| <button | |
| onClick={() => toggle(true)} | |
| > | |
| Open | |
| </button> | |
| {open && | |
| // Using React Suspense, the component is dynamically imported | |
| <Suspense fallback={<div>Loading...</div>}> | |
| <MenuContainer /> | |
| </Suspense> | |
| } | |
| </> | |
| ) | |
| } | |
| export { Navigation } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment