P
P
Pogran2016-09-21 16:54:28
React
Pogran, 2016-09-21 16:54:28

Why doesn't it completely change props?

ran into an odd problem.
Here I have such a structure state prntscr.com/ckmzj6
reducer looks like this (this is the action of changing the structure)

const structure = state.structure;
      const { parentId, value, key } = action;
      const nodeId = Object.keys(structure).length;
      structure[nodeId] = {
        id: nodeId,
        _key: key,
        _value: value,
        type: 'string',
        childIds: []
      };

      structure[parentId]._value = false;
      structure[parentId].type = "object";
      structure[parentId].childIds.push(nodeId);

      console.log(structure[parentId]);


      return {
        ...state,
        structure: structure
      };

the problem is that only structure[parentId].childIds.push(nodeId); changes come to the view;
but for some reason these lines are not displayed at all with changes in the view
structure[parentId]._value = false;
      structure[parentId].type = "object";

Everything changes in the state tree, so why then when I render, I see that only the childIds of the element has changed. how can i find this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Gushchin, 2016-09-22
@Pogran

Your problem is that you are mutating the object. redux, like react, is built on immutability. I gave you an example of how to do it .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question