Blame view

天文台pc/tianwentai-ui/node_modules/use-callback-ref/dist/es2019/assignRef.js 556 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /**
   * Assigns a value for a given ref, no matter of the ref format
   * @param {RefObject} ref - a callback function or ref object
   * @param value - a new value
   *
   * @see https://github.com/theKashey/use-callback-ref#assignref
   * @example
   * const refObject = useRef();
   * const refFn = (ref) => {....}
   *
   * assignRef(refObject, "refValue");
   * assignRef(refFn, "refValue");
   */
  export function assignRef(ref, value) {
      if (typeof ref === 'function') {
          ref(value);
      }
      else if (ref) {
          ref.current = value;
      }
      return ref;
  }