-
Couldn't load subscription status.
- Fork 6
Closed
Description
https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
useState accepts a default value OR a create function for the default value. If a function, it is evaluated only once. Thus, this entire pattern could simply be a convenience function:
import * as React from 'react' export default function useConstant<T>(fn: () => T): T { return React.useState<T>(fn)[0] }jakub-zawislak, wddwycc, christophehurpeau and garronejdantman
Metadata
Metadata
Assignees
Labels
No labels