useImmediateUpdateEffect

    API

    import useImmediateUpdateEffect from '@restart/hooks/useImmediateUpdateEffect'
    • useImmediateUpdateEffect(effect: EffectCallback, deps: DependencyList) => void

      An immediate effect that runs an effect callback when its dependency array changes. This is helpful for updates should must run during render, most commonly state derived from props; a more ergonomic version of https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops

      function Example({ value }) {
      const [intermediaryValue, setValue] = useState(value);
      useImmediateUpdateEffect(() => {
      setValue(value)
      }, [value])

      Parameters

      • effectEffectCallback
      • depsDependencyList

      Return Value void