Understand the static behavior of DataSheetGrid
masterBy default, <DataSheetGrid /> is static. This means it captures the props it receives during the first render and ignores subsequent changes to non-primitive props. This behavior is designed to prevent unnecessary re-renders when using inline objects, arrays, or functions (e.g., defining columns or createRow directly in the JSX).
Because of this, you can safely use inline props without performance penalties, but those props will not update the grid if they change later in the component lifecycle.
import { DataSheetGrid } from 'react-datasheet-grid'
const MyComponent = () => {
const [ data, setData ] = useState([])
return (
<DataSheetGrid
value={data}
onChange={setData}
columns={[
{/*...*/},
{/*...*/},
]}
createRow={() => ({ id: genId() })}
/>
)
}