refactor(graphcontext): memoize context
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState, memo } from 'react';
|
||||
import cx from 'classnames';
|
||||
|
||||
export default (props) => {
|
||||
@@ -41,4 +41,4 @@ export default (props) => {
|
||||
/>
|
||||
</g>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { createContext, useEffect, useReducer } from 'react';
|
||||
import React, { createContext, useEffect, useReducer, useMemo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import isEqual from 'lodash.isequal';
|
||||
|
||||
@@ -12,7 +12,6 @@ export const Provider = (props) => {
|
||||
const {
|
||||
elements,
|
||||
children,
|
||||
onConnect
|
||||
} = props;
|
||||
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
@@ -49,11 +48,10 @@ export const Provider = (props) => {
|
||||
}
|
||||
});
|
||||
|
||||
const graphContext = {
|
||||
const graphContext = useMemo(() => ({
|
||||
state,
|
||||
dispatch,
|
||||
onConnect,
|
||||
};
|
||||
dispatch
|
||||
}), [state]);
|
||||
|
||||
return (
|
||||
<GraphContext.Provider
|
||||
|
||||
@@ -21,6 +21,6 @@ const TargetHandle = memo((props) => {
|
||||
});
|
||||
|
||||
TargetHandle.displayName = 'TargetHandle';
|
||||
TargetHandle.whyDidYouRender = true;
|
||||
TargetHandle.whyDidYouRender = false;
|
||||
|
||||
export default TargetHandle;
|
||||
|
||||
Reference in New Issue
Block a user