useState() not rendering from redux, elements disappear
See original GitHub issueHi guys, for some weird reason, state is not updating based on updates from redux. I’ve implemented the following.
FC<...Props> = ({ dispatch, data }) => {
const [dataState, setDataState] = useState(data);
useEffect(() => {
setDataState(data);
}, [dispatch, data]);
return(
<ReactFlowProvider>
<ReactFlow elements={dataState}
...
)
}
And, in my Reducer. I would push a new element using:
case 'CREATE_ITEM':
return update(
state,
{
map: {
counter: { $set: state.map.counter + 1 },
data: {
$push: [{
id: state.map.counter + 1,
className: `context-${state.map.counter + 1}`,
animated: true,
type: 'default',
...
}],
}
},
},
);
In essence, after I update the state again. All elements disappear from the canvas.
Curious if you guys had any feedback, thank you!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Need help accessing state from useSelector, state disappears ...
1 Answer 1 ... I think you used the wrong property name. Where is state. todoList ? ... when I have state.todos it...
Read more >React.useEffect Hook – Common Problems and How to Fix ...
The infinite re-renders problem. The reason our component is re-rendering is because our useEffect dependency is constantly changing. But why?
Read more >Using the State Hook - React
A Hook is a special function that lets you “hook into” React features. For example, useState is a Hook that lets you add...
Read more >Understanding common frustrations with React Hooks
React Hooks can be frustrating despite their popularity and widespread use. Learn about some of the drawbacks to using React Hooks.
Read more >React.js — Basic Hooks (useState, useEffect, & useContext)
It's not that writing class-based components in JavaScript are a bad thing, ... useState(), as defined above, hooks state into a component.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I had the same issue, my problem was not to append the item to the existing array. Try the following for adding new items:
closed due to inactivity