How to dynamically add a childnode in syncfusion Treeview component React

Viewed 122

I am developing an application in react in which main screen has 3 split panes, [You can see the layout in this pic][1]. Now When i am adding a new file in testing folder from right side childnode state updates but changes is not rendering. I am using redux for that purpose. Here is my code: Action.js

  return {
    type: "addFolder",
    name: name,
  };
};

export const update = (sceneName, folder) => {
  return {
    type: "addScene",
    sceneName: sceneName,
    folder: folder,
  };
};```
Reducers:(overview)
```import { adds } from "./add";
const allReducer = combineReducers({
  addFolder: adds,```
```import sceneImage from "../static/images/scene.png";
import update from "react-addons-update";

var x = Math.floor(Math.random() * 100 + 1)
let obj = [
  {
    icon: "Geo",
    id: 1,
    name: "Testing",
    nodeChild: [
      { id: 2244, name: "Scene1", image: sceneImage },
      { id: 2244, name: "Scene2", image: sceneImage },
    ],
  },
];
export const adds = (state = obj, action) => {
  switch (action.type) {
    case "addFolder":
      return [
        ...state,
        {
          icon: "GEO",
          id: obj.length,
          name: action.name,
          nodeChild: [],
        },
      ];
    case "addScene":
      const newState = [...state];

      const objIndex = newState.findIndex((obj) => obj.id == action.folder);
      newState[0].nodeChild.push({
        id: 2244,
        name: action.sceneName,
        image: sceneImage,
      });

      return newState; //[...state, newState];

    default:
      return state;
  }
};```

Anyone please help me




  [1]: https://i.stack.imgur.com/NeKUy.png
1 Answers

After spending many hours i found a solution and i am sharing it here so that in future may be it will help others.

So the problem is my redux is updating the state correctly but syncfusion treeview component has an issue i-e it will not show changes unless we render the node again. So for dynamically adding the nodechild in treeview component you have to render the whole node again.

Related