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:

tailwind typography

How to use the Tailwind Typography plugin

Walk you through how to set up and use the Tailwind Typography plugin, also known as the @tailwindcss/typography or the prose plugin.

David Omotayo
May 7, 2025 ⋅ 7 min read
Running TypeScript In Node.js: Tsx Vs. Ts-node Vs. Native

Running TypeScript in Node.js: tsx vs. ts-node vs. native

TypeScript adds static typing to JavaScript code, which helps reduce unpredictable behavior and bugs. In the past, TypeScript code couldn’t […]

Amazing Enyichi Agu
May 7, 2025 ⋅ 8 min read
Authentication And Authorization In Astro

Authentication and authorization in Astro

Implement secure authentication and role-based authorization in Astro using JWT, SSR, and Astro middleware for protected routes.

Emmanuel John
May 6, 2025 ⋅ 23 min read
How To Use Custom Fonts In Tailwind CSS

How to use custom fonts in Tailwind CSS

Walk through how to use Google Fonts and locally installed fonts in your Tailwind projects to help you improve your project typography and design consistency.

Peter Ekene Eze
May 6, 2025 ⋅ 11 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