Skip to main content

useActionOnUnmount

Description#

With this hook you can kick of an action with data before the component unmounts.

Let's say someone adds some values to the inputs, and does not submit it. You could potentially submit the form before it unmounts with this hook.

Usage#

import { useCallback, useState } from 'react';import { useActionOnUnmount } from '@springtree/eva-suite-react-hooks';
const ExampleComponent = () => {  const [inputValue, setInputValue] = useState<string | unedfined>();
  const handleSubmit = useCallback(    (value: string | undefined) => {      console.log(value);      // update your store or use a service    },    [],  );
  const data = useActionOnUnmount<string>(    value,    handleSubmit,  );
  // ...};

References#