Skip to content

Instantly share code, notes, and snippets.

@pomber
Last active November 20, 2018 00:14
Show Gist options
  • Select an option

  • Save pomber/49d8998ac351a63af2e4845769d7cbc5 to your computer and use it in GitHub Desktop.

Select an option

Save pomber/49d8998ac351a63af2e4845769d7cbc5 to your computer and use it in GitHub Desktop.
class App extends React.Component {
state = {
selectedStock: null
};
render() {
const { stocks } = this.props;
const { selectedStock } = this.state;
return (
<React.Suspense fallback={<div>Loading...</div>}>
<StockTable
stocks={stocks}
onSelect={selectedStock => this.setState({ selectedStock })}
/>
{selectedStock && (
<StockChart
stock={selectedStock}
onClose={() => this.setState({ selectedStock: false })}
/>
)}
{/* Preload <StockChart/> */}
<React.Suspense fallback={null}>
<div hidden={true}>
<StockChart stock={stocks[0]} />
</div>
</React.Suspense>
</React.Suspense>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment