2023-02-13
2301
#react
Ohans Emmanuel
3053
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:

When to use CSS text-wrap: balance vs text-wrap: pretty

When to use CSS text-wrap: balance vs. text-wrap: pretty

Compare and contrast two CSS components, text-wrap: balance and text-wrap: pretty, and discuss their benefits for better UX.

Daniel Schwarz
Nov 7, 2025 ⋅ 5 min read

Remix 3 ditched React: Should you stick with it?

Remix 3 ditches React for a Preact fork and a “Web-First” model. Here’s what it means for React developers — and why it’s controversial.

Ikeh Akinyemi
Nov 7, 2025 ⋅ 4 min read

Autogen vs. Crew AI: Choosing the right agentic framework

A quick guide to agentic AI. Compare Autogen and Crew AI to build autonomous, tool-using multi-agent systems.

Kapeel Kokane
Nov 7, 2025 ⋅ 11 min read
ai dev tool power rankings

AI dev tool power rankings & comparison [Nov 2025]

Compare the top AI development tools and models of November 2025. View updated rankings, feature breakdowns, and find the best fit for you.

Chizaram Ken
Nov 6, 2025 ⋅ 9 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

Hey there, want to help make our blog better?

Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now