Search code examples
javascriptreactjsuse-statenew-operator

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


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


Solution

  • 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.