qlik-oss/sn-table

View on GitHub
src/table/hooks/use-selection-reducer.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { useReducer } from "react";

import { ExtendedSelectionAPI, Row } from "../../types";
import { SelectionDispatch, SelectionState } from "../types";
import { reducer } from "../utils/selections-utils";

const useSelectionReducer = (
  pageRows: Row[],
  selectionsAPI: ExtendedSelectionAPI | undefined,
): [SelectionState, SelectionDispatch] => {
  const [selectionState, selectionDispatch] = useReducer(reducer, {
    pageRows,
    rows: {},
    colIdx: -1,
    api: selectionsAPI,
    isSelectMultiValues: false,
  });

  return [selectionState, selectionDispatch];
};

export default useSelectionReducer;