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:

Building A Serverless Postgres-Powered GraphQL API With Neon Db, Prisma Orm, And Apollo Server

Building a serverless GraphQL API with NeonDB and Prisma

Combine NeonDB, Prisma ORM, and Apollo Server within a serverless architecture to achieve a fully functional and scalable GraphQL API.

Nitish Sharma
Feb 8, 2024 ⋅ 12 min read
Exploring Interaction To Next Paint, A New Core Web Vital

Exploring Interaction to Next Paint, a new Core Web Vital

Interaction to Next Paint was added to Google’s Core Web Vitals to provide a more comprehensive assessment of website interactivity.

Rahul Chhodde
Feb 7, 2024 ⋅ 6 min read
Starlight Vs. Docusaurus For Building Documentation

Starlight vs. Docusaurus for building documentation

Explore Docusaurus and Starlight for building and customizing documentation websites, comparing their features such as sidebars, light/dark mode, and tabs.

Kapeel Kokane
Feb 6, 2024 ⋅ 10 min read
Comparing Typescript State Management Solutions

Comparing TypeScript state management solutions

Dealing with state management in TypeScript provides benefits like type safety, code formatting, and error management.

Rashedul Alam
Feb 2, 2024 ⋅ 17 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