jianxiaoBai / react-json-editor-ui

React-based visual json editor.
https://jianxiaobai.github.io/react-json-editor-ui/
MIT License
46 stars 10 forks source link

`data` works just as initial value. The component is not stateless #14

Closed MadMed677 closed 1 year ago

MadMed677 commented 1 year ago

Description

Based on the example: https://github.com/jianxiaoBai/react-json-editor-ui/blob/main/example/index.tsx#L46 the component should be stateless. We contain a state on the business level but JsonEditor just accepts the data and provides new data in the onChange callback. But it doesn't work. If you try to mock the onChange function and do not change your state the component will work. The problem is: I couldn't change the component state outside. If I need to provide different data based on my state I couldn't pass it into JsonEditor because the component will ignore it.

Question

Is this component should be stateless and this is a bug or it should contain state and it's impossible to change outside?

jianxiaoBai commented 1 year ago

I don't quite understand your question, so I'll try to answer it.

This data is the received value, which will be deeply cloned inside the source code to achieve data isolation. The component will split the received data and map it will be more complicated, so privatization of the data will make it easier to achieve There are fewer problems, so this data design is stateless, that's all.