Chart values and options doesn't trigger re-render
Manuelandro opened this issue · comments
Manuel Palma commented
Hello, i'm using the "optimal way" to update the chart when some props changes, but the chart doesn't re-render.
Am i doing something wrong?
export default function Chart({ series, navigator }) {
const [options, setOptions] = useState({
...
xAxis: { min: navigator.min, max: navigator.max },
series: series
});
useEffect(() => {
setOptions({ ...options, series: series });
}, [series])
useEffect(() => {
setOptions({ ...options, xAxis: { ...options.xAxis, min: navigator.min, max: navigator.max } });
}, [navigator])
return <HighchartsReact highcharts={Highcharts} options={options} />;
Paweł Potaczek commented
Hi @Manuelandro,
Thank you for contacting us!
I see that you unnecessary adding already applied options to chart update here: setOptions({ ...options, series: series });
It is enough to use: setOptions({ series });
However, I wasn't able to reproduce the problem by using your code. Please check the below live example and adapt it to show the issue.
Live demo: https://stackblitz.com/edit/react-mphu35?file=index.js
Best regards!
Paweł Potaczek commented
Closed due to inactivity.