mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
fix: use useMemo instead useLocalStore
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { observer, useLocalStore } from 'mobx-react';
|
||||
import { observer } from 'mobx-react';
|
||||
import { useMemo } from 'react';
|
||||
import styled, { css } from 'reshadow';
|
||||
|
||||
import { Loader } from '@cloudbeaver/core-blocks';
|
||||
@@ -53,12 +54,10 @@ export const ElementsTree: React.FC<Props> = observer(function ElementsTree({
|
||||
const nodeChildren = useChildren(root);
|
||||
const Placeholder = emptyPlaceholder;
|
||||
|
||||
const context = useLocalStore<ITreeContext, ITreeContext>(source => source, {
|
||||
control,
|
||||
onOpen,
|
||||
onSelect,
|
||||
isSelected,
|
||||
});
|
||||
const context = useMemo<ITreeContext>(
|
||||
() => ({ control, onOpen, onSelect, isSelected }),
|
||||
[control, onOpen, onSelect, isSelected]
|
||||
);
|
||||
|
||||
if (!nodeChildren.children || nodeChildren.children.length === 0) {
|
||||
if (nodeChildren.isLoading()) {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { observer, useLocalStore } from 'mobx-react';
|
||||
import { useRef } from 'react';
|
||||
import { observer } from 'mobx-react';
|
||||
import { useMemo, useRef } from 'react';
|
||||
import styled, { use } from 'reshadow';
|
||||
|
||||
import { useStyles } from '@cloudbeaver/core-theming';
|
||||
@@ -50,7 +50,7 @@ export const TreeNode: React.FC<Props> = observer(function TreeNode({
|
||||
handlersRef.current.onOpen?.();
|
||||
};
|
||||
|
||||
const nodeContext = useLocalStore<ITreeNodeContext, ITreeNodeContext>(source => source, {
|
||||
const nodeContext = useMemo<ITreeNodeContext>(() => ({
|
||||
loading,
|
||||
selected,
|
||||
expanded,
|
||||
@@ -58,16 +58,7 @@ export const TreeNode: React.FC<Props> = observer(function TreeNode({
|
||||
expand: handleExpand,
|
||||
select: handleSelect,
|
||||
open: handleOpen,
|
||||
});
|
||||
// const nodeContext = useMemo<ITreeNodeContext>(() => ({
|
||||
// loading,
|
||||
// selected,
|
||||
// expanded,
|
||||
// leaf,
|
||||
// expand: handleExpand,
|
||||
// select: handleSelect,
|
||||
// open: handleOpen,
|
||||
// }), [loading, selected, expanded, leaf, handleExpand, handleSelect, handleOpen]);
|
||||
}), [loading, selected, expanded, leaf, handleExpand, handleSelect, handleOpen]);
|
||||
|
||||
return styled(useStyles(TREE_NODE_STYLES))(
|
||||
<node as="div" {...use({ expanded })} className={className}>
|
||||
|
||||
Reference in New Issue
Block a user