useLatest

    0

    0

    maidangzhu

    The useLatest function takes a value and creates a reference to it. Then, it updates the "current" property of the reference to the given value.

    Library: react

    import { useRef } from 'react';
    
    import { useRef } from 'react';
    
    function useLatest<T>(value: T) {
      const ref = useRef(value);
      ref.current = value;
    
      return ref;
    }
    
    export default useLatest;
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.