1

I've been trying to make a simple chart generator in React. I use Handsontable to let the user enter dynamic data and I would like the changes to be reflected in the chart. Here is my code: Codesandbox reproducible.

Small disclaimer: the handsontable package is pretty buggy in codesandbox. Just double click a number and an inputfield will appear where you can edit data.

The problem

For some reason, you can only edit something from the first data row and the second data row (labels not included). After that, the chart won't update anymore. So try changing 11 under the Mercedes label and you will see what I mean. Those can be changed and the changes will be reflected in the chart, but any number changed after that won't update the chart.

Now I've read this github issue where people suggest to add a random key (key={Math.random()}) or the redraw prop, and that somewhat works, but the whole chart gets redrawn, which is not exactly what I want.

1 Answer 1

2

The problem was with mutating deep nested properties. I've used lodash clonedeep to deepclone the object. Then changing the contents of that object and setting the state. It all worked fine after that.

I updated the codesandbox reproduction in case someone needs it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.