UNPKG

@taro-hooks/ahooks

Version:
20 lines 565 B
import { useRef } from '@taro-hooks/core'; import { escapeState } from '@taro-hooks/shared'; import { depsAreSame } from '../utils'; export default function useCreation(factory, deps) { var creation = useRef({ deps: deps, obj: undefined, initialized: false }, // @ts-ignore true); if (escapeState(creation.current).initialized === false || !depsAreSame(escapeState(creation.current).deps, deps)) { creation.current = { deps: deps, obj: factory(), initialized: true }; } return escapeState(creation.current).obj; }