'How to multi select the row using the Shift + click in react js?

Code:-

const ClickHighlight = (event, id) => {
        if (event.ctrlKey) {
            // add to highlighted
            setHighlightedRows((current) => {
                if (current.includes(id)) {
                    // row is already highlighted. Unhighlight but keep the others                   
                    return current.filter((entry) => entry !== id);
                } else {
                    // add row to the current list of highlighted ones                                   
                    return [...current, id];

                }
            });

        } else if (event.shiftKey) {
            previousRow.push(id);
          
        }
        else {
            // highlight clicked row and de-highlight others
            setHighlightedRows([id]);
        }
    }

If user press Shift and ctrl then multiple row selected example 1 row clicked and then 2 last row between all row selected. PLEASE HELP.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source