View lazy-with-preload.js
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
function lazyWithPreload(factory) { | |
const Component = React.lazy(factory); | |
Component.preload = factory; | |
return Component; | |
} | |
const StockChart = lazyWithPreload(() => import("./StockChart")); | |
// somewhere in your component | |
... |
View App.jsx
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
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 |
View App.jsx
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 stockChartPromise = import("./StockChart"); | |
const StockChart = React.lazy(() => stockChartPromise); |
View __.babelrc
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
{ | |
"presets": ["@babel/preset-react", "@babel/preset-env"] | |
} |
View App.jsx
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
import React from "react"; | |
import StockTable from "./StockTable"; | |
import StockChart from "./StockChart"; | |
class App extends React.Component { | |
state = { | |
selectedStock: null | |
}; | |
render() { |
View suspense.jsx
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
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import fetchWithCache from "./cache"; | |
function Post({ postId }) { | |
const post = fetchWithCache( | |
"https://jsonplaceholder.typicode.com/posts/" + postId | |
); | |
return ( | |
<div> |
View componentDidMount.jsx
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
import React from "react"; | |
import ReactDOM from "react-dom"; | |
class Post extends React.Component { | |
state = { | |
loading: true, | |
post: null | |
}; | |
componentDidMount() { | |
const { postId } = this.props; |
View memo.jsx
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
function MyComponent(props) { | |
/* render using props */ | |
} | |
function areEqual(prevProps, nextProps) { | |
/* | |
return true if passing nextProps to render would return | |
the same result as passing prevProps to render, | |
otherwise return false | |
*/ | |
} |
View foo.py
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
def foo: | |
return 5 |
View __.babelrc
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
{ | |
"presets": ["@babel/preset-react", "@babel/preset-env"] | |
} |