dangerous-fuchsiaD
Refine2y ago
3 replies
dangerous-fuchsia

how to reset modal component state on close?

this is in my modal component:

interface Props {
  modalProps: ModalProps
  formProps: FormProps
  isFormLoading: boolean
}

export default function NotificationSettingsModal({ modalProps, formProps, isFormLoading }: Props) {
  const [isEnabled, setIsEnabled] = useState(false)

  return (
    <Modal {...modalProps} width={500} centered title='Notifications' closable={true} destroyOnClose>
      <Spin spinning={isFormLoading}>
        <Form {...formProps}>
          <Form.Item name='slack_notifier' valuePropName='checked'>
            <Checkbox onChange={(e) => setIsEnabled(e.target.checked)}>Enable Slack Notifications for this task</Checkbox>
          </Form.Item>
          {isEnabled && (
            <>
              <Divider />
              <Form.Item name='notify_client_slack_channel' valuePropName='checked'>
                <Checkbox>Notify client slack channel</Checkbox>
              </Form.Item>
            </>
          )}
        </Form>
      </Spin>
    </Modal>
  )
}


If the user closes the modal, I would want isEnabled to reset. I figured using destoryOnClose would fix this issue but it doesnt.
Was this page helpful?