Blame view

天文台pc/tianwentai-ui/node_modules/@mui/utils/esm/useLazyRef/useLazyRef.js 525 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  'use client';
  
  import * as React from 'react';
  const UNINITIALIZED = {};
  
  /**
   * A React.useRef() that is initialized lazily with a function. Note that it accepts an optional
   * initialization argument, so the initialization function doesn't need to be an inline closure.
   *
   * @usage
   *   const ref = useLazyRef(sortColumns, columns)
   */
  export default function useLazyRef(init, initArg) {
    const ref = React.useRef(UNINITIALIZED);
    if (ref.current === UNINITIALIZED) {
      ref.current = init(initArg);
    }
    return ref;
  }