Skip to main content

Introduction

All the hooks that are frequently used in the EVA Suite Modules are included in the eva-suite-react-hooks repo, and are distributed via NPM in the @springtree/eva-suite-react-hooks package.

Installation#

npm install --save @springtree/eva-suite-react-hooks

Usage#

You can use the package like this:

import { useState } from 'react';import { useDebounce } from '@springtree/eva-suite-react-hooks';
const Example = () => {  const [inputValue, setInputValue] = useState<string | undefined>();  const debouncedInputValue = useDebounce(inputValue, 500);
  return (    <>      <input        type="text"        value={inputValue ?? ''}        onChange={(event) => setInputValue(event.target.value)}      >      <span>        {`The debounced value is: ${debouncedValue}`}      </span>    </>  )};
export default Example;

Hooks list#

HookDescription
useActionOnUnmountWith this hook you can kick of an action with data before the component unmounts
useBooleanHandy custom hook which gives you callbacks to either update or toggle a boolean state value
useBoundingRectangleThis hook saves and returns the last known bounding box (position and dimensions) of a DOM element. It also updates on resize events.
useBuildIntentUrlHook to use the urlBuilder of the intentBuilder
useDebounceDebounce any state value with this hook
useEnumToArrayHook to convert an enum to an array
useEvaLoginHook that exposes handy helpers to login to EVA
useEvaMutationUse this hook to query an EVA service as a mutation (React Query SDK)
useEvaQueryUse this hook to query an EVA service (React Query SDK)
useEventListenerIf you find yourself adding a lot of event listeners using useEffect you might consider using this hook
useHasFunctionalityReturns if the user may or may not use an EVA functionality
useHotjarInitialize Hotjar for the application based on eva-config
useLocalStorageCustom hook that works just like useState, but based on localStorage
useNavigateToChildPathNavigate to a URL, that has the same prefix as the current URL (e.g. /api/users -> /api/users/3)
useParseStringToFloatParses a string value to a float or undefined
useParseStringToIntegerParses a string value to an integer or undefined
usePreviousGet the previous value of a state value
useRecoilDebouncedValueDebounce Recoil state setter
useSentrySetup Sentry in EVA app
useSetRequestHandles setting the service request with the newRequest only when it exists and is different than the current request
useSetResponseStaleSet service to stale once rendered
useLocaleUse this hook to manage the application locale
useUndoCustom hook for managing undo / redo on state values
useWhyDidYouUpdateThis hook makes it easy to see which prop changes are causing a component to re-render