Redrawing graph gives me errors

I am using react and I’ve been trying to redraw the graph when the user click on checkboxes to toggle the visibility of the lines. Here is the code that I’ve made to do that :

const legendToggle = (name, index, e) => {

    const isChecked =;
    const graphDiv = document.getElementById('graphId');
    if (isChecked) {[index].visible = true;
    } else {[index].visible = "legendonly";

But doing this gives me an error :