Skip to content

Commit cd2795b

Browse files
committed
fix: ensure reset button works multiple times in a row
1 parent 76c2721 commit cd2795b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/interface-default/src/form.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ const ConsentForm: React.FC<ConsentFormProps> = ({
5353
}, [integrations])
5454

5555
const defaultState = useMemo(() => {
56-
const initialState: FormState = {}
56+
const defaultState: FormState = {}
5757

5858
for (const integration of integrations) {
59-
initialState[integration.id] = integration.enabledByDefault || false
59+
defaultState[integration.id] = integration.enabledByDefault || false
6060
}
6161

62-
return initialState
62+
return defaultState
6363
}, [integrations])
6464

6565
const [formState, setFormState] = useState<FormState>(initialState)
@@ -75,9 +75,10 @@ const ConsentForm: React.FC<ConsentFormProps> = ({
7575
onSubmit({ enabled })
7676
}, [onSubmit, setFormVisible, formState])
7777

78-
const cbReset = useCallback(() => {
79-
setFormState(defaultState)
80-
}, [setFormState, initialState])
78+
const cbReset = useCallback(
79+
() => setFormState({ ...defaultState }),
80+
[setFormState, defaultState]
81+
)
8182

8283
const cbEnableAll = useCallback(() => {
8384
setFormState((state) => {

0 commit comments

Comments
 (0)