Skip to content

Commit

Permalink
Remove basevalue
Browse files Browse the repository at this point in the history
  • Loading branch information
Esteban Beltran committed Feb 16, 2022
1 parent ff64286 commit 9cf248d
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions x-pack/plugins/cases/public/components/cases_context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useState, useEffect, useReducer, useMemo } from 'react';
import React, { useState, useEffect, useReducer } from 'react';
import { merge } from 'lodash';
import { DEFAULT_FEATURES } from '../../../common/constants';
import { DEFAULT_BASE_PATH } from '../../common/navigation';
Expand Down Expand Up @@ -46,18 +46,17 @@ export const CasesProvider: React.FC<{ value: CasesContextProps }> = ({
}) => {
const { appId, appTitle } = useApplication();
const [state, dispatch] = useReducer(casesContextReducer, initialCasesContextState());
const [baseValue, setBaseValue] = useState<Omit<CasesContextStateValue, 'state' | 'dispatch'>>(
() => ({
owner,
userCanCrud,
basePath,
/**
* The empty object at the beginning avoids the mutation
* of the DEFAULT_FEATURES object
*/
features: merge({}, DEFAULT_FEATURES, features),
})
);
const [value, setValue] = useState<CasesContextStateValue>(() => ({
owner,
userCanCrud,
basePath,
/**
* The empty object at the beginning avoids the mutation
* of the DEFAULT_FEATURES object
*/
features: merge({}, DEFAULT_FEATURES, features),
dispatch,
}));

/**
* `userCanCrud` prop may change by the parent plugin.
Expand All @@ -66,7 +65,7 @@ export const CasesProvider: React.FC<{ value: CasesContextProps }> = ({
*/
useEffect(() => {
if (appId && appTitle) {
setBaseValue((prev) => ({
setValue((prev) => ({
...prev,
appId,
appTitle,
Expand All @@ -75,10 +74,6 @@ export const CasesProvider: React.FC<{ value: CasesContextProps }> = ({
}
}, [appTitle, appId, userCanCrud]);

const value = useMemo(() => {
return { ...baseValue, dispatch };
}, [baseValue]);

return isCasesContextValue(value) ? (
<CasesContext.Provider value={value}>
<CasesContextUI state={state} />
Expand Down

0 comments on commit 9cf248d

Please sign in to comment.