use-immer | Use immer to drive state with a React hooks | Frontend Utils library
kandi X-RAY | use-immer Summary
kandi X-RAY | use-immer Summary
Use immer to drive state with a React hooks
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of use-immer
use-immer Key Features
use-immer Examples and Code Snippets
Community Discussions
Trending Discussions on use-immer
QUESTION
I am trying to move my propsValue into new array.
There are 2 buttons in my codes, first button(Convert them) executes the transfer. second button(print All) prints every key and value of Users
however, my "print all" button prints undefined after the transfer.
How should I modify my codes to contain correct values?
Thank you
...ANSWER
Answered 2021-Mar-24 at 05:38There are multiple things that is wrong with this.
1st. The reason its undefined
is because you are trying to display a data it does not have. You want to display property name
via temp.name
in your console.log("THe Users: ", temp.name, " : ", temp.key))
But look at the object struture - it has no property name
. it has value
and key
. So this is first issue.
2nd. The variable user
, from the hook, updates AFTER all of the map
and re-renders. Meaning, the entire time inside the map
, the user
remains the default user
data aka empty. Hooks should be used when it is required to re-render the component after the data change. Hence should just create a variable instead of using a hook.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install use-immer
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page