home ~ projects ~ socials

Lazy initializer for useState

const [thing, setThing] = useState(() => { some_expensive_operation ? 'yes' : 'no' })

If you pass a function as the argument to useState() it'll use that for the initial load and only call that when necessary instead of on each render

TODO: Confirm that code snippet

-- end of line --