Cannot read properties of null (reading 'offsetWidth')
apexchart updateOptions
사용하는 과정에서 에러가 발생했다.
아래는 작업중이던 코드다.
if (chartInstance) {
chartInstance.updateOptions({
series: chartSeries,
...chartOptions,
legend: {
...chartOptions.legend,
// chartRef.current.offsetWidth 에서 에러 발생
width: chartRef.current?.offsetWidth - (document.querySelector('div.apexcharts-toolbar') ? document.querySelector('div.apexcharts-toolbar').getBoundingClientRect().width : 0),
...
},
...
});
}
해당 이슈는 chartInstance 가 존재하는 상태이지만 실제 chartRef 의 값이 없을 때 offsetWidth 를 가져오려고 해서 발생한 에러였다.
상위 if 문에 해당 조건을 추가처리함으로서 문제를 해결했다.