Ohans Emmanuel
Feb 13, 2023 ⋅ 8 min read

How to initialize state using React Hooks

Ohans Emmanuel Visit me at ohansemmanuel.com to learn more about what I do!

Recent posts:

Leveraging Wasp For Full-Stack Development

Leveraging Wasp for full-stack development

Learn how the Wasp, Web Application Specification, framework simplifies full-stack development by offloading repetitive code tasks.

Wisdom Ekpotu
May 27, 2024 ⋅ 11 min read
Developing Web Extensions With Wxt

Developing web extensions with the WXT library

Browser extensions are an important part of the web ecosystem. They make our lives easier and enhance our web browsing […]

Debjyoti Banerjee
May 24, 2024 ⋅ 8 min read
Bulma Css Adoption Guide: Overview, Examples, And Alternatives

Bulma CSS adoption guide: Overview, examples, and alternatives

Explore how Bulma CSS simplifies frontend development with its ease of use and customizable, responsive, pre-designed UI elements.

Timonwa Akintokun
May 23, 2024 ⋅ 10 min read
Using Mountaineer To Develop A React App With Python

Using Mountaineer to develop a React app with Python

Develop a React app with Python using the Mountaineer framework for building a simple app with integrated your frontend and backend database.

Rosario De Chiara
May 23, 2024 ⋅ 7 min read
View all posts

4 Replies to "How to initialize state using React Hooks"

  1. You’d typically use this pattern in conjunction with more interesting patterns such as control props/state reducer etc. Regardless, this pattern exists to make it easier to initialise and reset state within your reusable components.

  2. For me in the useCounter I have to return array instead of object

    return [count, setCount];

    else wil get the Invalid attempt to destructure non-iterable instance error

  3. Your custom hook will return an invalid function or return value is not iterable error because you return an object and not an array.

    you should do this.
    return [count, setCount, reset];

Leave a Reply