Skip to content

Commit

Permalink
fix: ensure reset button works multiple times in a row
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Feb 26, 2024
1 parent 76c2721 commit cd2795b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/interface-default/src/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ const ConsentForm: React.FC<ConsentFormProps> = ({
}, [integrations])

const defaultState = useMemo(() => {
const initialState: FormState = {}
const defaultState: FormState = {}

for (const integration of integrations) {
initialState[integration.id] = integration.enabledByDefault || false
defaultState[integration.id] = integration.enabledByDefault || false
}

return initialState
return defaultState
}, [integrations])

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

const cbReset = useCallback(() => {
setFormState(defaultState)
}, [setFormState, initialState])
const cbReset = useCallback(
() => setFormState({ ...defaultState }),
[setFormState, defaultState]
)

const cbEnableAll = useCallback(() => {
setFormState((state) => {
Expand Down

0 comments on commit cd2795b

Please sign in to comment.