Git Product home page Git Product logo

Comments (5)

fritz-c avatar fritz-c commented on July 18, 2024

Hm.. I designed it so that it would update to reflect any changes in the state, without having to explicitly trigger anything. Are you modifying the object in-place?
e.g.,

this.state.myTree[3].bar = "foo";
this.setState({ myTree: this.state.myTree });

Every data operation I did in the library (and in the tree data APIs) did something more like

const index = 3;
this.setState({ myTree: [
    ...this.state.myTree.slice(0, index),
    { ...this.state.myTree[index], bar: "foo" },
    ...this.state.myTree.slice(index + 1),
] });

I forget, but I think that's called a pure function, or treating objects as immutable.

If this doesn't help, do you mind posting the relevant parts of your code?

from react-sortable-tree.

mojo5000 avatar mojo5000 commented on July 18, 2024

Thanks for the expedient reply. Revised what I posted prior. Did it your way, worked. Still grokking why and immutability... :)

from react-sortable-tree.

fritz-c avatar fritz-c commented on July 18, 2024

Glad to hear!
More so than my library, I think it might have something to do with how React detects changes in state. Assigning new values to an object without recreating it makes it so the previous reference is unchanged, and objects are passed around by reference (I think).

Here's a little proof-of-concept from the terminal:

$ node
> a = {b: 1}
{ b: 1 }
> c = a
{ b: 1 }
> c.b = 2
2
> a === c
true

from react-sortable-tree.

anil1712 avatar anil1712 commented on July 18, 2024

Hi,
How do we get index?
Can we use treeIndex to modify the tree node title?

Actually I just wanted to change the title of any node. Please suggest me how to achieve this.

@fritz-c can you please look into it. How do I update any tree node title by uisng the treeIndex for path?

Thanks

from react-sortable-tree.

kpgbrink avatar kpgbrink commented on July 18, 2024

So I should be able to use the functions like addNodeUnderParent when hosting this in a PureComponent with no issue?

from react-sortable-tree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.