Performance
Code Example
function App() {
const [range, setRange] = useState(DEFAULT_TIMEFRAME);
const debouncedRange = useDeferredValue(range);
...
return (
<TimelineContext
onDragEnd={onDragEnd}
onResizeEnd={onResizeEnd}
range={debouncedRange} // provide the debounced range
onRangeChanged={setRange}
>
<Timeline items={items} rows={rows} />
</TimelineContext>
)function Item(props: ItemProps) {
...
const style: CSSProperties = {
...itemStyle,
transition: 'left .2s linear, width .2s linear',
// You can a CSS transition to make the debounce feel smoother
}
return (
<div ref={setNodeRef} style={style} {...listeners} {...attributes}>
...
</div>
)
}Code Example
function App() {
const [range, setRange] = useState(DEFAULT_TIMEFRAME);
const debouncedRange = useThrottle(range, 300);
...
return (
<TimelineContext
onDragEnd={onDragEnd}
onResizeEnd={onResizeEnd}
range={debouncedRange} // provide the debounced range
onRangeChanged={setRange}
>
<Timeline items={items} rows={rows} />
</TimelineContext>
)function Item(props: ItemProps) {
...
const style: CSSProperties = {
...itemStyle,
transition: 'left .2s linear, width .2s linear',
// You can a CSS transition to make the debounce feel smoother
}
return (
<div ref={setNodeRef} style={style} {...listeners} {...attributes}>
...
</div>
)
}Live Example
Last updated