mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
17 lines
564 B
TypeScript
17 lines
564 B
TypeScript
import _range from 'lodash/range';
|
|
import React from 'react';
|
|
|
|
export default function useChartLegend(dataLength: number) {
|
|
const [ selectedLines, setSelectedLines ] = React.useState<Array<number>>(_range(dataLength));
|
|
|
|
const handleLegendItemClick = React.useCallback((index: number) => {
|
|
const nextSelectedLines = selectedLines.includes(index) ? selectedLines.filter((item) => item !== index) : [ ...selectedLines, index ];
|
|
setSelectedLines(nextSelectedLines);
|
|
}, [ selectedLines ]);
|
|
|
|
return {
|
|
selectedLines,
|
|
handleLegendItemClick,
|
|
};
|
|
}
|