fix: use useMemo instead useLocalStore

This commit is contained in:
Wroud
2020-10-21 19:00:28 +03:00
parent ea6d143517
commit b646a6da81
2 changed files with 10 additions and 20 deletions
@@ -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}>