Files
react/components/table/table-context.ts
witt 80956b0cc8 chore: release v2.1.0-canary.3 (#450)
* docs: add link to GH discussions

* chore: upgrade deps

* chore: update code style for prettier

* chore: release v2.1.0-canary.3

* chore(deps): upgrade babel

* chore: replace enzyme adapter with community repo to fit react.17

* test: updatee snapshots for auto typesetting

* test(config): ignore unexported parts of the tools
2021-02-14 15:27:37 +08:00

24 lines
561 B
TypeScript

import React from 'react'
export type TableColumnItem = {
value: string
label: React.ReactNode | string
width?: number
}
export interface TableConfig {
columns: Array<TableColumnItem>
updateColumn?: (column: TableColumnItem) => void
removeRow?: (rowIndex: number) => void
updateRow?: (rowIndex: number, newData: any) => void
}
const defaultContext = {
columns: [],
}
export const TableContext = React.createContext<TableConfig>(defaultContext)
export const useTableContext = (): TableConfig =>
React.useContext<TableConfig>(TableContext)