mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-19 08:20:30 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f829cd0222 | ||
|
|
0a03ea3a75 | ||
|
|
0aa55dac08 | ||
|
|
15778fe467 |
@@ -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:
|
||||
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
|
||||
@@ -304,8 +304,8 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
disablePageResetOnDataChange,
|
||||
},
|
||||
useFilters,
|
||||
useSortBy,
|
||||
useGroupBy,
|
||||
useSortBy,
|
||||
useExpanded,
|
||||
usePagination,
|
||||
useRowSelect
|
||||
|
||||
+1
-1
@@ -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",
|
||||
|
||||
@@ -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
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user