Last active
December 26, 2018 03:12
-
-
Save JNaeemGitonga/73aba165af5455967b5198fb6ca9d7c3 to your computer and use it in GitHub Desktop.
example of lazy-loading and using context-api together pt. 3.
This file contains 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
const Form = React.lazy(() => import('./form/form')); | |
class App extends Component { | |
state = { | |
open: false, | |
} | |
handleClick = () => { | |
this.setState({ open: true }); | |
} | |
render() { | |
return ( | |
<Grid | |
container | |
className={styles.App} | |
direction="row" | |
justify="center" | |
alignItems="center" | |
> | |
< Button | |
onClick={ () => this.handleClick() } | |
variant="contained" | |
color="primary" | |
>Click Me</Button> | |
{ | |
this.state.open && ( | |
<Suspense fallback={<CircularProgress />}> | |
<Form/> | |
</Suspense> | |
) | |
} | |
</Grid> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment