Skip to content

Commit

Permalink
Uses useRef for lastSpecificScope
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Mar 28, 2023
1 parent 82943a1 commit b92f123
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import React, { FC, useCallback, useState } from 'react';
import React, { FC, useCallback, useRef, useState } from 'react';
import {
NativeFilterScope,
styled,
Expand Down Expand Up @@ -67,8 +67,7 @@ const FilterScope: FC<FilterScopeProps> = ({
const [initialFilterScope] = useState(
filterScope || getDefaultScopeValue(chartId, initiallyExcludedCharts),
);
const [lastSpecificScope, setLastSpecificScope] =
useState(initialFilterScope);
const lastSpecificScope = useRef(initialFilterScope);
const [initialScopingType] = useState(
isScopingAll(initialFilterScope, chartId)
? ScopingType.all
Expand All @@ -81,7 +80,7 @@ const FilterScope: FC<FilterScopeProps> = ({
const onUpdateFormValues = useCallback(
(formValues: any) => {
if (formScopingType === ScopingType.specific) {
setLastSpecificScope(formValues.scope);
lastSpecificScope.current = formValues.scope;
}
updateFormValues(formValues);
setHasScopeBeenModified(true);
Expand Down Expand Up @@ -121,7 +120,7 @@ const FilterScope: FC<FilterScopeProps> = ({
const scope =
value === ScopingType.all
? getDefaultScopeValue(chartId)
: lastSpecificScope;
: lastSpecificScope.current;
updateFormValues({ scope });
setHasScopeBeenModified(true);
forceUpdate();
Expand Down

0 comments on commit b92f123

Please sign in to comment.