@omnigrid/react 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/useGrid.js +16 -0
  2. package/package.json +1 -1
package/dist/useGrid.js CHANGED
@@ -28,6 +28,22 @@ export function useGrid(options) {
28
28
  const subscribe = useCallback((listener) => grid.subscribe(listener), [grid]);
29
29
  const getSnapshot = useCallback(() => grid.getState(), [grid]);
30
30
  const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
31
+ // Reconcile plugins when the plugin list changes. Plugins removed from the
32
+ // list are unregistered (their cleanup restores default behavior); new ones
33
+ // are registered. Declared before the data sync so that, on a switch, the
34
+ // old plugin is gone before data is replaced and the new one is attached
35
+ // before the new data arrives. The first run is skipped: the Grid
36
+ // constructor already registered the initial plugins.
37
+ const pluginsSyncedRef = useRef(false);
38
+ useEffect(() => {
39
+ if (grid.isDestroyed())
40
+ return;
41
+ if (!pluginsSyncedRef.current) {
42
+ pluginsSyncedRef.current = true;
43
+ return;
44
+ }
45
+ grid.setPlugins(options.plugins);
46
+ }, [grid, options.plugins]);
31
47
  // Sync data when the data reference changes (async load, pagination,
32
48
  // parent-side filtering). Skip on the first run — the Grid constructor
33
49
  // already initialised data from options.data. Only sync on subsequent
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",