The purpose of this guide is to help you to create your own UI Hooks.
- Node: any 8.x version.
yarn
ornpm
installed.- A clone of the react-ui-hooks repo on your local machine, following the example:
git clone https://github.com/your-username/react-ui-hooks.git
.
- First things first, if you want to create a new hook, you have to give it a name that starts with
use
and then the name of the hook, such as useModal, useSlider, etc. - if you try create a hook without this pattern, you'll get an error.
The generate:hook
command create 3 files:
- A hook file useExample.js
- The tests file useExample.test.js
- The documentation file useExample.md
The hook and tests files must be updated manually, the documentation file can be updated all at once by using the generate:docs
command .
- Open your shell and run the command:
npm run generate:hook useExample
or
yarn generate:hook useExample
useExample.js on src/hooks/
useExample.test.js on src/tests/hooks
useExample.md on docs/
If you've created your hook manually you can generate its unit test file with the command:
npm run generate:test useExample.js
or
yarn generate:test useExample.js
You can get the doc file of your hook created automaticaly as well!
npm run generate:docs useExample.js
or
yarn generate:docs useExample.js
As you update the hooks and tests frequently there's a need to update the documentation, so you can do it for all of the hooks with:
npm run generate:docs
or
yarn generate:docs
This command scans your hooks and its tests to generate the documentation.