Lazy Initial State
Pass a function to useState to run expensive setup only once.
Example
const [data] = useState(() => JSON.parse(localStorage.getItem("d") || "[]"));Exercise
Function initialiser.
useState(() 0)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.