Skip to content

Commit

Permalink
[TreeView] Fix hydration error
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Oct 17, 2024
1 parent 54cde58 commit a58814d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ export const useTreeViewId: TreeViewPlugin<UseTreeViewIdSignature> = ({
state,
setState,
}) => {
const treeId = state.id.treeId;

React.useEffect(() => {
setState((prevState) => {
if (prevState.id.treeId === params.id) {
if (params.id === prevState.id.providedTreeId && prevState.id.treeId !== undefined) {
return prevState;
}

Expand All @@ -23,6 +21,8 @@ export const useTreeViewId: TreeViewPlugin<UseTreeViewIdSignature> = ({
});
}, [setState, params.id]);

const treeId = state.id.treeId ?? state.id.providedTreeId;

return {
getRootProps: () => ({
id: treeId,
Expand All @@ -37,4 +37,4 @@ useTreeViewId.params = {
id: true,
};

useTreeViewId.getInitialState = ({ id }) => ({ id: { treeId: id ?? createTreeViewDefaultId() } });
useTreeViewId.getInitialState = ({ id }) => ({ id: { treeId: undefined, providedTreeId: id } });
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export type UseTreeViewIdDefaultizedParameters = UseTreeViewIdParameters;

export interface UseTreeViewIdState {
id: {
treeId: string;
treeId: string | undefined;
providedTreeId: string | undefined;
};
}

Expand Down

0 comments on commit a58814d

Please sign in to comment.