Skip to content

Instantly share code, notes, and snippets.

@MauricioRobayo
Last active October 16, 2022 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MauricioRobayo/eb9f7e1cada77097d06809a4a38c0345 to your computer and use it in GitHub Desktop.
Save MauricioRobayo/eb9f7e1cada77097d06809a4a38c0345 to your computer and use it in GitHub Desktop.
The initialState argument is the state used during the initial render. In subsequent renders, it is disregarded. If the initial state is the result of an expensive computation, you may provide a function instead, which will be executed only on the initial render:
const [state, setState] = useState(() => {
const initialState = someExpensiveComputation(props);
return initialState;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment