diff --git a/.size-snapshot.json b/.size-snapshot.json index 501adcf..41a8f18 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,13 +1,13 @@ { "dist/index.js": { - "bundled": 98780, - "minified": 48107, - "gzipped": 12496 + "bundled": 97093, + "minified": 46881, + "gzipped": 12344 }, "dist/index.es.js": { - "bundled": 97724, - "minified": 47164, - "gzipped": 12312, + "bundled": 96528, + "minified": 46389, + "gzipped": 12228, "treeshaked": { "rollup": { "code": 78, diff --git a/CHANGELOG.md b/CHANGELOG.md index 79663a9..c8ec2e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 7.0.0-beta.27 + +- Added the `useControlledState` option, which allows for hook-context control of the resolved internal table state + ## 7.0.0-beta.26 - Fixed an issue where the table would crash if useSortBy was reset via the resetSortBy action diff --git a/README.md b/README.md index 99d426a..d2d5d66 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,9 @@ Enjoy this library? Try them all! [React Query](https://github.com/tannerlinsley - [Installation](./docs/installation.md) - Walk through how to install React Table - [Concepts](./docs/concepts.md) - Read how React Table works and how you can use it better - [Examples](./docs/examples.md) - Experience and learn from some examples and guides of how to use React Table and implement common patterns -- [API](./docs/api.md) - Get to know React Table's API, how to use it and how to extend its functionality -- [Using V6 Still?](#v6-info) +- [API](./docs/api.md) - Get to know React Table's API +- [FAQ](./docs/faq.md) - Learn how to use React Table for specific challenges and tasks +- [Previous Versions](#previous-versions) - [Contributing](./CONTRIBUTING.md) - Become familiar with how to contribute back to React Table - [Code of Conduct](./CODE_OF_CONDUCT.md) - Be a good React Table citizen by following these repository rules @@ -194,11 +195,11 @@ This library is being built and maintained by me, @tannerlinsley and I am always ### [Become a Sponsor](https://github.com/sponsors/tannerlinsley/) -## v6 Info +## Previous Versions -#### I'm still using v6, what should I do? +### Version 6 -v6 is a great library and while it is still available for use, I do not intend on offering any long-term support for it. If you intend to keep using v6, I recommend maintaining your own fork of the library and keeping it up to date for your version of React. +v6 is a great library and while it is still available to install and use, I am no longer offering any long-term support for it. If you intend to keep using v6, I recommend maintaining your own fork of the library and keeping it up to date for your version of React. #### Where are the docs for the older v6 version? @@ -208,4 +209,4 @@ Please [visit the v6 branch](https://github.com/tannerlinsley/react-table/tree/v The differences between the 2 versions are incredibly massive. Unfortunately, I cannot write a one-to-one upgrade guide for any of v6's API, simply because much of it is irrelevant with v7's headless approach. The best approach for migrating to v7 is to learn its API by reading the documentation and then following some of the examples to begin building your own table component. -In case you would need to have both v6 and v7 in one app during the migration process (large codebase, complex use cases), you can install an official [`react-table-6` package](https://www.npmjs.com/package/react-table-6) alongside the `react-table`. +In case you would need to have both v6 and v7 in one app during the migration process (large codebase, complex use cases), you can either (1) fork and maintain your own local version of React Table v6 or (2) install the [`react-table-6` alias package](https://www.npmjs.com/package/react-table-6) for use alongside the `react-table` package. diff --git a/docs/api.md b/docs/api.md index ae3eece..cb8e66d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -92,6 +92,12 @@ The following options are supported via the main options object passed to `useTa - With every action that is dispatched to the table's internal `React.useReducer` instance, this reducer is called and is allowed to modify the final state object for updating. - It is passed the `newState`, `action`, and `prevState` and is expected to either return the `newState` or a modified version of the `newState` - May also be used to "control" the state of the table, by overriding certain pieces of state regardless of the action. +- `useControlledState: HookFunction(state) => controlledState` + - Optional + - If you need to control part of the table state, this is the place to do it. + - This function is run on every single render, just like a hook and allows you to alter the final state of the table if necessary. + - You can use hooks inside of this function, but most of the time, we just suggest using `React.useMemo` to memoize your state overrides. + - See the FAQ ["How can I manually control the table state?"](./faq.md#how-can-i-manually-control-the-table-state) for a an example. - `defaultColumn: Object` - Optional - Defaults to `{}` diff --git a/docs/faq.md b/docs/faq.md new file mode 100644 index 0000000..c04d23f --- /dev/null +++ b/docs/faq.md @@ -0,0 +1,29 @@ +# FAQ + +Below are some of the most frequently asked questions on how to use the React Table API to solve various table challenges you may encounter + +
Selected Rows: {selectedRowPaths.length}
- {/*+> ) } diff --git a/package.json b/package.json index 3f3a7a9..1bdefe6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-table", - "version": "7.0.0-beta.26", + "version": "7.0.0-beta.27", "description": "A fast, lightweight, opinionated table and datagrid built on React", "license": "MIT", "homepage": "https://github.com/tannerlinsley/react-table#readme", diff --git a/sizes-cjs.json b/sizes-cjs.json index eb048b7..1384690 100644 --- a/sizes-cjs.json +++ b/sizes-cjs.json @@ -1,4 +1,14 @@ [ + { + "timestamp": 1575517726476, + "files": [ + { + "filename": "index.js", + "size": 20569, + "delta": 58 + } + ] + }, { "timestamp": 1575391465436, "files": [ diff --git a/sizes-es.json b/sizes-es.json index d0444d6..6273f4b 100644 --- a/sizes-es.json +++ b/sizes-es.json @@ -1,4 +1,14 @@ [ + { + "timestamp": 1575517715056, + "files": [ + { + "filename": "index.es.js", + "size": 20427, + "delta": 59 + } + ] + }, { "timestamp": 1575391457318, "files": [ diff --git a/src/hooks/useTable.js b/src/hooks/useTable.js index 631da3d..59983db 100755 --- a/src/hooks/useTable.js +++ b/src/hooks/useTable.js @@ -23,6 +23,7 @@ const defaultColumnInstance = {} const defaultReducer = (state, action, prevState) => state const defaultGetSubRows = (row, index) => row.subRows || [] const defaultGetRowId = (row, index) => index +const defaultUseControlledState = d => d export const useTable = (props, ...plugins) => { // Destructure props @@ -34,6 +35,7 @@ export const useTable = (props, ...plugins) => { getSubRows = defaultGetSubRows, getRowId = defaultGetRowId, reducer: userReducer = defaultReducer, + useControlledState = defaultUseControlledState, debug, } = props @@ -57,10 +59,14 @@ export const useTable = (props, ...plugins) => { } // But use the users table state if provided - const [state, originalDispatch] = React.useReducer(reducer, undefined, () => - reducer(initialState, { type: actions.init }) + const [reducerState, originalDispatch] = React.useReducer( + reducer, + undefined, + () => reducer(initialState, { type: actions.init }) ) + const state = useControlledState(reducerState) + // The table instance ref let instanceRef = React.useRef({})Selected Rows: {selectedRowPaths.size}
+*/} +{JSON.stringify( { @@ -92,7 +92,7 @@ function Table({ columns, data }) { 2 )}-