Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Latest commit

 

History

History
34 lines (28 loc) · 1.24 KB

Usage.md

File metadata and controls

34 lines (28 loc) · 1.24 KB

Usage

You need to have React 16.8.0 or later installed to use the Hooks API. You can import each hook individually

import useNfd from 'awesomealgo-hooks/lib/useNfd'

or use ES6 named imports (tree shaking recommended)

import { useNfd } from 'awesomealgo-hooks'

Depending on your bundler you might run into a missing dependency error with ES6 named import statements. Some hooks require you to install peer dependencies so we recommend using individual imports. If you want the best of both worlds you can transform the named import statements to individual import statements with babel-plugin-import by adding the following config to your .babelrc file:

[
      'import',
      {
        libraryName: 'awesomealgo-hooks',
        camel2DashComponentName: false,
        customName(/** @type {string} */ name) {
          const libraryDirectory = name.startsWith('Use')
            ? 'lib/component'
            : name.startsWith('create')
            ? 'lib/factory'
            : 'lib'
          return `awesomealgo-hooks/${libraryDirectory}/${name}`
        }
      },
      'import-awesomealgo-hooks'
    ]