DEV Community


Posted on

useDispatch deos not re-render my component

I was using redux with data strecture looks like this

mydata = {id:'1', name:'the name ishere", children:[{id:'0',name:'name",children:[...]}]}
Enter fullscreen mode Exit fullscreen mode

later I convert my data structure to look like this

mydata = [{id:string, name:string, children:[]} ,{...}]
Enter fullscreen mode Exit fullscreen mode

and of course, I change my code to suits this new structure, but I face tow problems after that

  1. the first problem is the component doesn't re-render after I use dispatch I even used a usestate inside the updating function in tree.tsx line 17 just to rerender the component
  2. the second problem is there is a function called adding() that don't work properly any more.
  3. you can notice that by seeing reducer.tsx line 88 where i console.log(state) and the logged state actually new state but in line 134 the logged state is not not effected by the adding function
  4. codesnadbox

Top comments (0)