Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component assumes that the data prop is mutated, not replaced #4

Open
richiec opened this issue Sep 29, 2019 · 1 comment
Open

Component assumes that the data prop is mutated, not replaced #4

richiec opened this issue Sep 29, 2019 · 1 comment

Comments

@richiec
Copy link

richiec commented Sep 29, 2019

If you're using this with Redux, the data prop may be taken from the redux store, in which case it will be a new array each time (not the original array mutated). This means that as elements are added and removed to the tree, the component doesn't update. To get around this, when binding a container component to the store, be sure to use a key prop to signal the change. For example:

<TreeView data={props.data} key={props.data.length === 0 ? -1 : props.data[0].id}/>

@tubbybtch
Copy link

This is a really tricky issue, If populating by a prop, it will either not update or crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants