You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useMemo.js 356 B

3 years ago
1234567891011
  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. }