'React hook stuck on previous object value
I have a list of objects I am creating and updating with useState:
{
id: list1.length + 1,
key: list1.length + 1,
variable: userInput.variable,
name: userInput.name,
value: userInput.value,
}
When I set the value of name: to "text", the value changes and updates to "variable", which is a value that has been previously and commonly used. When I looked through the Chrome debugger the value never changed and was correct, "text", however, when I console.log() the value it shows me "variable". Another strange thing is that after I add an item to this list of objects, the debugger will show a changed value in name: for the previous items in the list.
The biggest kicker is that I went through all my code and hard coded in "text" into the value for name: and guess what? It still shows as "variable". Is there some sort of cache in React? Or maybe there is a bug?
Solution 1:[1]
As it turns out, I just needed to post on Stack Overflow to finally solve the issue. I have an if statement
{itemsList.map((item) => {
if ((item.name = "variable")) {
And it was functioning as both an if statement and an assignment operator because I forgot to put in the second set of = .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jacob |
