From 8f062550aad1377618b30f4a4f129a6b1012acf8 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Fri, 18 May 2018 17:32:04 -0600 Subject: [PATCH] v6.8.3 --- CHANGELOG.md | 6 ++++++ README.md | 16 ++++++++++++++++ package.json | 2 +- src/defaultProps.js | 1 + src/methods.js | 3 ++- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4751b26..52a497e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.8.3 + +#### Fixes & Optimizations + +* Allow the `resolveData` prop to alter or materialize new data when the `data` prop changes. + ## 6.8.1 #### Fixes & Optimizations diff --git a/README.md b/README.md index 56a5cca..8dba5ad 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,21 @@ render() { Simply pass the `data` prop anything that resembles an array or object. Client-side sorting and pagination are built in, and your table will update gracefully as you change any props. [Server-side data](#server-side-data) is also supported! +```javascript + +``` + +**Pro Tip: Using the `resolveData` prop** - Any time the `data` prop value changes (using a `===` comparison), the table will update, but sometimes you need to materialize, alter, or shape this data before it enters the table. To do this, you can use the `resolveData` prop! It recieves the `data` prop as the only parameter and returns the resolved data. + +```javascript + data.map(row => row)} // But you can break immutability here because `resolveData` runs when the `data` prop changes! +/> +``` + ## Props These are all of the available props (and their default values) for the main `` component. @@ -169,6 +184,7 @@ These are all of the available props (and their default values) for the main ` resolvedData, loading: false, showPagination: true, showPaginationTop: false, diff --git a/package.json b/package.json index 8a36eef..f83b07e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-table", - "version": "6.8.2", + "version": "6.8.3", "description": "A fast, lightweight, opinionated table and datagrid built on React", "license": "MIT", "homepage": "https://github.com/react-tools/react-table#readme", diff --git a/src/defaultProps.js b/src/defaultProps.js index 82dd618..59338e4 100644 --- a/src/defaultProps.js +++ b/src/defaultProps.js @@ -9,6 +9,7 @@ const emptyObj = () => ({}) export default { // General data: [], + resolveData: data => data, loading: false, showPagination: true, showPaginationTop: false, diff --git a/src/methods.js b/src/methods.js index cc567cb..508059e 100644 --- a/src/methods.js +++ b/src/methods.js @@ -18,6 +18,7 @@ export default Base => columns, pivotBy = [], data, + resolveData, pivotIDKey, pivotValKey, subRowsKey, @@ -237,7 +238,7 @@ export default Base => } return row } - let resolvedData = data.map((d, i) => accessRow(d, i)) + let resolvedData = resolveData(data).map((d, i) => accessRow(d, i)) // TODO: Make it possible to fabricate nested rows without pivoting const aggregatingColumns = allVisibleColumns.filter(d => !d.expander && d.aggregate)