UNPKG

@douyinfe/semi-ui

Version:

A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.

13 lines 378 B
import { useRef, useState } from 'react'; // https://github.com/facebook/react/issues/14543 export default function useStateWithGetter(initial) { const ref = useRef(); const [state, setState] = useState(initial); ref.current = state; const set = value => { ref.current = value; setState(value); }; const get = () => ref.current; return [state, set, get]; }