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 />
);
}