d2321
3/21/2020 - 11:18 AM

Lazy Loading React 16.6

state={showPosts:false};
modeHandler = () => {
  this.setState(prevState => {
    return {showPosts: !prevState.showPosts}
  });
}

//

state = { showPosts: false };
modeHandler = () => {
  this.setState(prevState => {
    return { showPosts: !prevState.showPosts };
  });
};
<button onClick={this.modeHandler}>Toggle Mode</button>;
{
  this.state.showPosts ? (
    <Suspense fallback={<div>Loading...</div>}>
      <Posts></Posts>
    </Suspense>
  ) : (
    <User />
  );
}