Compare commits

...
Author SHA1 Message Date
tannerlinsley f829cd0222 v7.0.0-alpha.35 2019-09-09 08:25:09 -06:00
tannerlinsley 0a03ea3a75 fix: better flexRender utility (supports JSX elements now) 2019-09-09 08:24:08 -06:00
tannerlinsley 0aa55dac08 fix: fixed disablePageResetOnDataChangeRef dependencies
disablePageResetOnDataChangeRef will no longer trigger page resets when changed
2019-09-09 08:21:15 -06:00
Eddie HongandTanner Linsley 15778fe467 Fix typo in installation.md (#1498) 2019-09-06 10:59:47 -06:00
6 changed files with 32 additions and 13 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ $ npm install react-table@next
$ yarn add react-table@next
```
> NOTE: `@next` is only required tempororarily while work on the alpha and beta versions are still shifting.
> NOTE: `@next` is only required temporarily while work on the alpha and beta versions are still shifting.
To import React Table:
+4 -4
View File
@@ -230,17 +230,17 @@ function App() {
const [data, setData] = React.useState(() => makeData(20))
const [originalData] = React.useState(data)
const [skipPageReset, setSkipPageReset] = React.useState(false)
// We need to keep the table from resetting the pageIndex when we
// Update data. So we can keep track of that flag with a ref.
const skipPageResetRef = React.useRef(false)
// When our cell renderer calls updateMyData, we'll use
// the rowIndex, columnID and new value to update the
// original data
const updateMyData = (rowIndex, columnID, value) => {
// We also turn on the flag to not reset the page
skipPageResetRef.current = true
setSkipPageReset(true)
setData(old =>
old.map((row, index) => {
if (index === rowIndex) {
@@ -258,7 +258,7 @@ function App() {
// so that if data actually changes when we're not
// editing it, the page is reset
React.useEffect(() => {
skipPageResetRef.current = false
setSkipPageReset(false)
}, [data])
// Let's add a data resetter/randomizer to help
@@ -272,7 +272,7 @@ function App() {
columns={columns}
data={data}
updateMyData={updateMyData}
disablePageResetOnDataChange={skipPageResetRef.current}
disablePageResetOnDataChange={skipPageReset}
/>
</Styles>
)
+1 -1
View File
@@ -304,8 +304,8 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
disablePageResetOnDataChange,
},
useFilters,
useSortBy,
useGroupBy,
useSortBy,
useExpanded,
usePagination,
useRowSelect
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "react-table",
"version": "7.0.0-alpha.34",
"version": "7.0.0-alpha.35",
"description": "A fast, lightweight, opinionated table and datagrid built on React",
"license": "MIT",
"homepage": "https://github.com/tannerlinsley/react-table#readme",
+9 -2
View File
@@ -49,8 +49,15 @@ function useMain(instance) {
const isPageIndexMountedRef = React.useRef()
// Bypass any effects from firing when this changes
const disablePageResetOnDataChangeRef = React.useRef()
disablePageResetOnDataChangeRef.current = disablePageResetOnDataChange
safeUseLayoutEffect(() => {
if (isPageIndexMountedRef.current && !disablePageResetOnDataChange) {
if (
isPageIndexMountedRef.current &&
!disablePageResetOnDataChangeRef.current
) {
setState(
old => ({
...old,
@@ -60,7 +67,7 @@ function useMain(instance) {
)
}
isPageIndexMountedRef.current = true
}, [setState, rowDep, filters, groupBy, sortBy, disablePageResetOnDataChange])
}, [setState, rowDep, filters, groupBy, sortBy])
const pageCount = manualPagination
? userPageCount
+16 -4
View File
@@ -265,10 +265,22 @@ export function getElementDimensions(element) {
}
export function flexRender(Comp, props) {
if (typeof Comp === 'function' || typeof Comp === 'object') {
return <Comp {...props} />
}
return Comp
return isReactComponent(Comp) ? <Comp {...props} /> : Comp
}
function isClassComponent(component) {
return (
typeof component === 'function' &&
!!Object.getPrototypeOf(component).isReactComponent
)
}
function isFunctionComponent(component) {
return typeof component === 'function'
}
function isReactComponent(component) {
return isClassComponent(component) || isFunctionComponent(component)
}
export const mergeProps = (...groups) => {