RJV does not reflect back the json in tree when json state is changed
See original GitHub issueI am using React JSON View to dynamically update the source object linked with the tree. However I am not able to do so because it doesn’t take into account the changes in the object through state change. Hence, I see the old json even though new keys are added or removed. Here’s a small example showing the behaviour, what I want here is that whenever the setInterval calls the add function and adds a key to the json object, it should show that key in the tree as well.
Note: When I collapse and expand the tree again, it does show the updated json.
import React from 'react';
import ReactDOM from 'react-dom';
import ReactJsonView from 'react-json-view'
class JSONViewer extends React.Component {
constructor(props) {
super(props);
this.state = {json: {
Name: 'Kamesh',
Age: 23,
Array: [1, 2, 3]
}};
}
render() {
return (
<div>
<ReactJsonView src={this.state.json}/>
</div>
);
}
componentDidMount() {
setInterval(
() => {
let x = Math.random();
this.add(Object.assign(this.state.json, {
[x]: 'RandomKey'
}))
},
3000
);
}
add(newJSON) {
this.setState({
json: newJSON
});
}
}
ReactDOM.render(<JSONViewer />, document.getElementById('root'));
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
java - JSON order mixed up - Stack Overflow
If you add this to your JSONObject then the resulting JSON would be in the same order as you have created it. import...
Read more >react-json-view - npm
Name Type Default
src JSON Object None
name string or false "root"
theme string "rjv‑default"
Read more >Populating the tree using JSON - jsTree
The format remains the same as the above, the only difference is that the JSON is not inside the config object, but returned...
Read more >Convert a JSON File to an Array in React - Pluralsight
Make sure that it has a string value coming from a server or the local source. If so, then the parse function will...
Read more >Internals: JSON Output Format | Terraform
Terraform provides a machine-readable JSON representation of state, configuration and plan. ... e.g. "2.0" , for changes that are not backward-compatible.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This works well 😃
I encountered the same problem and could solve it by parsing the JSON string to an actual JSON object:
This did’nt work:
<ReactJson src={this.state.label} theme="monokai"/>
This works:
<ReactJson src={JSON.parse(this.state.label)} theme="monokai"/>
Best regards, Sven