@headless-tree/react 0.0.0-20250514161759 → 0.0.0-20250611124731
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.
- package/CHANGELOG.md +15 -9
- package/lib/cjs/use-tree.js +10 -5
- package/lib/esm/use-tree.js +11 -6
- package/package.json +2 -2
- package/src/use-tree.tsx +20 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
# @headless-tree/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20250611124731
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e2faf37: Fixed an issue async data loaders that resolve data before the tree is mounted can cause the tree to not render at all
|
|
8
|
+
|
|
9
|
+
Note: When using the `createTree()` API directly instead of going through the React `useTree` API, an additional call
|
|
10
|
+
to `tree.rebuildItems()` afterwards will be necessary. This change is marked as minor release regardless, since `createTree` is
|
|
11
|
+
currently not a publically documented feature.
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
6
14
|
|
|
7
|
-
- Updated dependencies [
|
|
8
|
-
- Updated dependencies [
|
|
9
|
-
- Updated dependencies [
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- Updated dependencies [cd5b27c]
|
|
14
|
-
- @headless-tree/core@0.0.0-20250514161759
|
|
15
|
+
- Updated dependencies [727c982]
|
|
16
|
+
- Updated dependencies [2887b0c]
|
|
17
|
+
- Updated dependencies [e2faf37]
|
|
18
|
+
- @headless-tree/core@0.0.0-20250611124731
|
|
19
|
+
|
|
20
|
+
## 1.1.0
|
|
15
21
|
|
|
16
22
|
## 1.0.1
|
|
17
23
|
|
package/lib/cjs/use-tree.js
CHANGED
|
@@ -6,11 +6,16 @@ const core_1 = require("@headless-tree/core");
|
|
|
6
6
|
const useTree = (config) => {
|
|
7
7
|
const [tree] = (0, react_1.useState)(() => ({ current: (0, core_1.createTree)(config) }));
|
|
8
8
|
const [state, setState] = (0, react_1.useState)(() => tree.current.getState());
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} })))
|
|
9
|
+
(0, react_1.useEffect)(() => {
|
|
10
|
+
tree.current.rebuildTree();
|
|
11
|
+
}, [tree]); // runs only once after mount
|
|
12
|
+
(0, react_1.useInsertionEffect)(() => {
|
|
13
|
+
tree.current.setConfig((prev) => (Object.assign(Object.assign(Object.assign({}, prev), config), { state: Object.assign(Object.assign({}, state), config.state), setState: (state) => {
|
|
14
|
+
var _a;
|
|
15
|
+
setState(state);
|
|
16
|
+
(_a = config.setState) === null || _a === void 0 ? void 0 : _a.call(config, state);
|
|
17
|
+
} })));
|
|
18
|
+
});
|
|
14
19
|
return tree.current;
|
|
15
20
|
};
|
|
16
21
|
exports.useTree = useTree;
|
package/lib/esm/use-tree.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useInsertionEffect, useState } from "react";
|
|
2
2
|
import { createTree } from "@headless-tree/core";
|
|
3
3
|
export const useTree = (config) => {
|
|
4
4
|
const [tree] = useState(() => ({ current: createTree(config) }));
|
|
5
5
|
const [state, setState] = useState(() => tree.current.getState());
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} })))
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
tree.current.rebuildTree();
|
|
8
|
+
}, [tree]); // runs only once after mount
|
|
9
|
+
useInsertionEffect(() => {
|
|
10
|
+
tree.current.setConfig((prev) => (Object.assign(Object.assign(Object.assign({}, prev), config), { state: Object.assign(Object.assign({}, state), config.state), setState: (state) => {
|
|
11
|
+
var _a;
|
|
12
|
+
setState(state);
|
|
13
|
+
(_a = config.setState) === null || _a === void 0 ? void 0 : _a.call(config, state);
|
|
14
|
+
} })));
|
|
15
|
+
});
|
|
11
16
|
return tree.current;
|
|
12
17
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-tree/react",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20250611124731",
|
|
4
4
|
"main": "lib/cjs/index.js",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/esm/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"typescript": "^5.7.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@headless-tree/core": "0.0.0-
|
|
31
|
+
"@headless-tree/core": "0.0.0-20250611124731",
|
|
32
32
|
"react": "*",
|
|
33
33
|
"react-dom": "*"
|
|
34
34
|
}
|
package/src/use-tree.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useInsertionEffect, useState } from "react";
|
|
2
2
|
import { TreeConfig, TreeState, createTree } from "@headless-tree/core";
|
|
3
3
|
|
|
4
4
|
export const useTree = <T,>(config: TreeConfig<T>) => {
|
|
@@ -7,19 +7,25 @@ export const useTree = <T,>(config: TreeConfig<T>) => {
|
|
|
7
7
|
tree.current.getState(),
|
|
8
8
|
);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
...
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
tree.current.rebuildTree();
|
|
12
|
+
}, [tree]); // runs only once after mount
|
|
13
|
+
|
|
14
|
+
useInsertionEffect(() => {
|
|
15
|
+
tree.current.setConfig((prev) => ({
|
|
16
|
+
...prev,
|
|
17
|
+
...config,
|
|
18
|
+
state: {
|
|
19
|
+
// ...prev.state,
|
|
20
|
+
...state,
|
|
21
|
+
...config.state,
|
|
22
|
+
},
|
|
23
|
+
setState: (state) => {
|
|
24
|
+
setState(state);
|
|
25
|
+
config.setState?.(state);
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
23
29
|
|
|
24
30
|
return tree.current;
|
|
25
31
|
};
|