Files
react/components/table/table-context.ts
witt 4062d7b5a8 refactor(table): redesign interfaces to improve the experience in TypeScript (#569)
* refactor(table): redesign interfaces to improve the experience in TypeScript

* docs: upgrade to new type exports

* style: fix lint warnings
2021-08-13 17:11:24 +08:00

18 lines
471 B
TypeScript

import React from 'react'
import { TableAbstractColumn } from './table-types'
export interface TableConfig<T> {
columns: Array<TableAbstractColumn<T>>
updateColumn: (column: TableAbstractColumn<T>) => void
}
const defaultContext = {
columns: [],
updateColumn: () => {},
}
export const TableContext = React.createContext<TableConfig<any>>(defaultContext)
export const useTableContext = <T>(): TableConfig<T> =>
React.useContext<TableConfig<T>>(TableContext)