Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useSetState add lazy initialization #2479

Open
AntonS86 opened this issue Feb 20, 2023 · 2 comments
Open

useSetState add lazy initialization #2479

AntonS86 opened this issue Feb 20, 2023 · 2 comments

Comments

@AntonS86
Copy link

please add lazy initialization like in useState hook

// useState
const [state, setState] = useState(() => {
  const initialState = someExpensiveComputation(props);
  return initialState;
});

// useSetState
const [state, setState] = useSetState(() => ({cnt: 0}));
@Bidhu1024
Copy link

I can fix this. Please assign it to me.

@dovidweisz
Copy link
Contributor

This actually already works. (initialState is just passed to setState)

It's just a matter of updating the types to allow it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants