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.

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