# All files / src/_hooks Deprecation.tsx

100% Statements 9/9
76.92% Branches 10/13
100% Functions 2/2
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    4450x

    50x
    717x
    239x

    239x
    70x

    7x
    7x

    7x

     import React from 'react'

    interface Config {
      /**
       * @since 10.19.0
       */
      when?: any
      /**
       * @since 10.19.0
       */
      oldThing: string
      /**
       * @since 10.19.0
       */
      newThing?: string
      /**
       * @since 10.19.0
       */
      link?: string
    }

    /* HOOK */

    /**
     * @deprecatedSince 9
     * @deprecated Never officially documented/supported
     */
    export function useDeprecation(config: Config) {
      const { oldThing, newThing, link } = config
      let when = 'when' in config ? typeof config.when !== 'undefined' : true

      React.useLayoutEffect(() => {
        if (
          when &&
          ['test', 'development'].indexOf(process.env.NODE_ENV || '') >= 0
        ) {
          const notice = `${oldThing} is deprecated`
          const recommendation = newThing ? `, please use ${newThing}` : ''

          console.warn(`${notice}${recommendation}`, link ?? '')
        }
      }, [when, newThing, oldThing, link])
    }