Also use PureDatagridRow to speed up SongDatagrid
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React, { isValidElement, useMemo, useCallback } from 'react'
|
import React, { isValidElement, useMemo, useCallback } from 'react'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { Datagrid, PureDatagridBody, DatagridRow } from 'react-admin'
|
import { Datagrid, PureDatagridBody, PureDatagridRow } from 'react-admin'
|
||||||
import { TableCell, TableRow, Typography } from '@material-ui/core'
|
import { TableCell, TableRow, Typography } from '@material-ui/core'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
@@ -96,13 +96,13 @@ export const SongDatagridRow = ({
|
|||||||
colSpan={childCount + (rest.expand ? 1 : 0)}
|
colSpan={childCount + (rest.expand ? 1 : 0)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<DatagridRow
|
<PureDatagridRow
|
||||||
record={record}
|
record={record}
|
||||||
{...rest}
|
{...rest}
|
||||||
className={clsx(className, classes.row)}
|
className={clsx(className, classes.row)}
|
||||||
>
|
>
|
||||||
{fields}
|
{fields}
|
||||||
</DatagridRow>
|
</PureDatagridRow>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,4 +23,5 @@ export * from './Title'
|
|||||||
export * from './SongBulkActions'
|
export * from './SongBulkActions'
|
||||||
export * from './useAlbumsPerPage'
|
export * from './useAlbumsPerPage'
|
||||||
export * from './useInterval'
|
export * from './useInterval'
|
||||||
|
export * from './useTraceUpdate'
|
||||||
export * from './Writable'
|
export * from './Writable'
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { useRef, useEffect } from 'react'
|
||||||
|
|
||||||
|
export function useTraceUpdate(props) {
|
||||||
|
const prev = useRef(props)
|
||||||
|
useEffect(() => {
|
||||||
|
const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
|
||||||
|
if (prev.current[k] !== v) {
|
||||||
|
ps[k] = [prev.current[k], v]
|
||||||
|
}
|
||||||
|
return ps
|
||||||
|
}, {})
|
||||||
|
if (Object.keys(changedProps).length > 0) {
|
||||||
|
console.log('Changed props:', changedProps)
|
||||||
|
}
|
||||||
|
prev.current = props
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user