Since hooks I've been splitting these up in to separate useState calls (one for each property). Is there an advantage of keeping it in a single object?
Yes, I can, thanks!
Just wonder why this is not implemented in react.
But you have a little issue in your example.
You use current state, not the last state in you fragment.
Be careful with sequential updates or use callback in setState call to reference prevState
Missed the useState call. Fixed now. I imagine it's not been implemented because they're going for a more minimalist approach. I.e. By giving us the simplest of hooks we can as above create more complex behaviours if we need.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Since hooks I've been splitting these up in to separate useState calls (one for each property). Is there an advantage of keeping it in a single object?
You are right, better example is required here.
P.S. Example updated, thanks
I see. You could achieve this with a custom hook.
Something like (am on phone so forgive mistakes please) :
Yes, I can, thanks!
Just wonder why this is not implemented in react.
But you have a little issue in your example.
You use current state, not the last state in you fragment.
Be careful with sequential updates or use callback in setState call to reference prevState
Missed the useState call. Fixed now. I imagine it's not been implemented because they're going for a more minimalist approach. I.e. By giving us the simplest of hooks we can as above create more complex behaviours if we need.