3

Can we use useState() at multiple time or is there any limit to use it in single component in React Js.

  • 1
    You can call it as many times as you like, as long as you follow the [rules of hooks](https://reactjs.org/docs/hooks-rules.html) – Nicholas Tower Jul 11 '22 at 13:57
  • 2
    If there's any kind of limit, it's going to be based on available resources and unrelated to the `useState` hook itself. More to the point, what happens when you *try*? Do you encounter any kind of problem? – David Jul 11 '22 at 13:59

1 Answers1

3

You can use useState multiple times. In fact it's even recommended in the React docs.
https://reactjs.org/docs/hooks-faq.html#should-i-use-one-or-many-state-variables

we recommend to split state into multiple state variables based on which values tend to change together.

I am not aware of any limit to its use.

Nice Books
  • 1,675
  • 2
  • 17
  • 21