Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

11 rindas
356 B

  1. import * as React from 'react';
  2. export default function useMemo(getValue, condition, shouldUpdate) {
  3. var cacheRef = React.useRef({});
  4. if (!('value' in cacheRef.current) || shouldUpdate(cacheRef.current.condition, condition)) {
  5. cacheRef.current.value = getValue();
  6. cacheRef.current.condition = condition;
  7. }
  8. return cacheRef.current.value;
  9. }