Ochuko Onojakpor
Feb 2, 2024 ⋅ 7 min read

Using React useState with an object

Ochuko Onojakpor Ochuko is a full-stack Python/React software developer and freelance Technical Writer. He spends his free time contributing to open source and tutoring students on programming in collaboration with Google DSC.

Recent posts:

Superglue Vs. Hotwire For Modern Frontend Development

Superglue vs. Hotwire for modern frontend development

Explore how Superglue and Hotwire revolutionize frontend development with HTML over the wire, enhancing performance, flexibility, and ease of use.

Frank Joseph
Jun 12, 2024 ⋅ 7 min read
Using Pocketbase To Build A Full Stack Application

Using PocketBase to build a full-stack application

PocketBase is a performant Go-based tool that comes with essential features like user auth, file uploads, access control rules, and more.

Rahul Padalkar
Jun 11, 2024 ⋅ 18 min read
The Top Tools For Implementing E-Commerce Search In React

The top tools for implementing e-commerce search in React

Explore top frontend tools for implementing e-commerce search functionality with React demo implementations.

Saleh Mubashar
Jun 10, 2024 ⋅ 7 min read
Signals Vs Ngonchanges For Better Angular State Management

Signals vs. ngOnChanges for better Angular state management

Angular is evolving in some exciting ways. Explore how signals enhance state management compared to the “old” approach using ngOnChanges.

Lewis Cianci
Jun 7, 2024 ⋅ 6 min read
View all posts

2 Replies to "Using React <code>useState</code> with an object"

  1. Hey. You should wrap callbacks in useCallback, especially in real apps that become larger. Then, you’ll need to pass current state as dependency into that hook, which makes the approach almost obsolete.
    The solution and important lesson: setState(current => ({…current, …next}))
    Use a function to set the state, and you’ll get the current one for free, without it being a dependency of the callback hook.

  2. let updatedValue = {};
    updatedValue = {“item1″:”juice”};

    why not in one statement :

    let updatedValue = {“Item1″:”juice”}

Leave a Reply