Can I use with class component?
How to use react-table with react component class?
Yes, just wrap your usage of useTable (and any other hooks) in a functional component and then reference that functional component from your class component.
I am using class-based components throughout my project. To use the react-table I did the same as suggested above. I created a function-based component using useTable hook and used the functional component in the class based component. Still I face the below problem.
Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)
Has anyone been able to get this to work?
I'm not...
Could someone provide any example?
me also stopped on this issue
just few lines of code there react down on hooks issue (need to provide hooksand method for state controlling to a useTable instance constructor)
// Use the state and functions returned from useTable to build your UI
const {
getTableProps,
getTableBodyProps,
headerGroups,
prepareRow,
page,
canPreviousPage,
canNextPage,
pageOptions,
pageCount,
gotoPage,
nextPage,
previousPage,
setPageSize,
state: { pageIndex, pageSize }
} = useTable({
columns: ...........,
data: [],
defaultColumn: undefined,
getRowId<D>(originalRow: D, relativeIndex: number, parent: Row<D> | undefined): string {
return "";
},
getSubRows<D>(originalRow: D, relativeIndex: number): D[] {
return [];
},
initialState: undefined,
stateReducer<D>(newState: TableState<D>, action: ActionType, previousState: TableState<D>, instance: TableInstance<D> | undefined): TableState<D> {
return undefined;
},
useControlledState<D>(state: TableState<D>, meta: Meta<D>): TableState<D> {
return undefined;
}
},
useFilters,
useGroupBy,
useSortBy,
useExpanded,
usePagination,
useRowSelect );
@tannerlinsley please reopen this issue, sure i cant find working example for classed component.
i runned with classed component, based on @ggascoigne suggestion, but this doesnt looks like tiny, better if project will be support with classed react component. i know its possible but need to write all needable methods for initiate useTables for me is difficult with time reason.