Skip to content

Performance of dynamic grid #192

Answered by nick-keller
DoHoangYen asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @DoHoangYen ,
Yes you should wrap non-primitive types in useMemo when using DynamicDataSheetGrid, with hooks it looks like that:

const [showColumn, setShowColumn] = useState(true)

const columns = useMemo(() => showColumn ? [{/*...*/}, {/*...*/}] : [{/*...*/}], [showColumn])

return <DynamicDataSheetGrid columns={columns} />

Here I have a state showColumn that is a boolean for this example, but it could be anything really. Based on showColumn I return an array with two or one column. I add showColumn as a dependency of useMemo to re-compute the columns when showColumn changes.

This way columns will only be updated when showColumn changes.

If you are using class components you can us…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by nick-keller
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants