Performance of dynamic grid #192
-
Hi, thank for your wonderful component.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @DoHoangYen , const [showColumn, setShowColumn] = useState(true)
const columns = useMemo(() => showColumn ? [{/*...*/}, {/*...*/}] : [{/*...*/}], [showColumn])
return <DynamicDataSheetGrid columns={columns} /> Here I have a state This way If you are using class components you can use the state I guess, doing this.setState({ columns: this.state.columns.push({/* add column */}) }) // ❌
this.setState({ columns: [...this.state.columns, {/* add column */}] }) // ✅ |
Beta Was this translation helpful? Give feedback.
-
Thank for the quick reply :) |
Beta Was this translation helpful? Give feedback.
Hello @DoHoangYen ,
Yes you should wrap non-primitive types in useMemo when using
DynamicDataSheetGrid
, with hooks it looks like that:Here I have a state
showColumn
that is a boolean for this example, but it could be anything really. Based onshowColumn
I return an array with two or one column. I addshowColumn
as a dependency of useMemo to re-compute the columns whenshowColumn
changes.This way
columns
will only be updated whenshowColumn
changes.If you are using class components you can us…