-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f74e347
commit 92603b6
Showing
13 changed files
with
49 additions
and
821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,5 @@ | ||
# Using TypeScript with React-Table | ||
|
||
React-table is a very flexible library, because of this, the shape of data at almost every contact point is defined by the specific set of plugins that you choose to pass to `useTable`. | ||
Types for React Table are maintained externally by the Typescript community and are located at https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-table. | ||
|
||
To get started, copy the file `react-table-config.d.ts` into your source tree (e.g. into a types folder). This expands the default types with all of the plugin extensions currently in the type definitions. | ||
|
||
You can stop here if you like, but while this is simple, it's a bit misleading. Out of the box, these types will suggest that you have access to values that come from plugins that you aren't using, i.e. the error checking is weakened. | ||
|
||
To bring the resulting types into better alignment with your plugins, you should edit your local copy of `react-table-config.d.ts` and comment out all of the interfaces that don't apply to your chosen set of plugins. | ||
|
||
e.g. | ||
|
||
if you are only using `useSortBy` and `usePagination` then you would take this: | ||
|
||
```tsx | ||
extends UseExpandedOptions<D>, | ||
UseFiltersOptions<D>, | ||
UseGroupByOptions<D>, | ||
UsePaginationOptions<D>, | ||
UseRowSelectOptions<D>, | ||
UseSortByOptions<D>, | ||
UseFiltersOptions<D>, | ||
UseResizeColumnsOptions<D>, | ||
Record<string, any> {} | ||
``` | ||
|
||
and convert it to this: | ||
|
||
```tsx | ||
export interface TableOptions<D extends object> | ||
extends UsePaginationOptions<D>, | ||
UseSortByOptions<D> {} | ||
``` | ||
|
||
Then follow the same pattern for all of the other interfaces in the file. You'll notice that many plugins don't extend all of the top-level interfaces. | ||
|
||
## Caveat | ||
|
||
The interfaces are all global. If you have several different configurations for the table, you should create interfaces using the union of all of the plugins that you are using. | ||
Because React Table is not written in Typescript and the types are not maintained by the core team, there are no guarantees around the types always being up to date or working perfectly. If this is an issue for you, please contribute to the community types and discuss solutions there. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.