First of all, thanks for being willing to contribute to @react-hookz
, the collective creating and
using this library appreciates that.
If you are contributing for the first time - we would recommend reading First Contributions guide first.
- Fork the main repo
- Clone repo to your computer (add
--depth=1
togit clone
command to save time) - Change folder to just cloned repo:
cd ./web
- Install dependencies:
yarn
- Make sure everything builds and tests:
yarn build && yarn test
- Create the branch for your PR, like:
git checkout -b pr/my-awesome-hook
- in case you are adding a new hook - it is better to name your branch by the hook:
pr/useUpdateEffect
- in case your change fixes an issue - it is better to name branch by the issue id:
pr/fix-12345
- in case you are adding a new hook - it is better to name your branch by the hook:
- Follow the directions below
Tip: to keep your
master
branch pointing at the original repo'smaster
(instead of your fork'smaster
) do this:git remote add upstream https://github.com/react-hookz/web.git git fetch upstream git branch --set-upstream-to=upstream/master masterAfter running these commands you'll be able to easily pull changes from the original repository by
git pull
.
- Implement the hook in
src
folder.- File should be named after the hook and placed in subdirectory also named after the hook.
- Hook should have return types explicitly defined.
- Hook should have JSDoc containing hook description and an overview of its arguments.
- Hook should be exported by name, not default exported.
- In case hook has some custom types as arguments or return values - it should also be exported.
- Types and interfaces should not have prefixes like
I
orT
(it is only left in existing code for compatibility reasons and will be removed). - Hook should be developed with SSR in mind.
- In case hook is stateful and exposes
setState
method, or is has async callbacks (that can theoretically be resolved after component unmount), it should useuseSafeState
instead ofuseState
. - In case of hooks reuse, import them as
import { useSafeState } from '..';
instead ofimport { useSafeState } from '../useSafeState/useSafeState';
- Reexport hook implementation and all custom types in
src/index.ts
.- Custom types should be also reexported.
- Write complete tests for your hook, tests should consist of both DOM and SSR parts.
- Hook's test should be placed in
__tests__
sub-folder, near the source file,dom.ts
for DOM environment,ssr.ts
for SSR environment.
4ex:src/useFirstMountState/__tests__/dom.ts
andsrc/useFirstMountState/__tests__/ssr.ts
. - Ideally your hook should have 100% test coverage. For cases where that is impossible, you should comment above the code exactly why it is impossible to have 100% coverage.
- Each hook should have at least 'should be defined' and 'should render' tests in
SSR
environment. - All utility functions should also be tested.
- Hook's test should be placed in
- Write docs for your hook.
- Docs should be placed in
__docs__
sub-folder, near the source file.
4ex:src/useFirstMountState/__docs__/story.mdx
. - Docs are built with storybook, to help you during writing docs - start webserver with
yarn storybook:watch
. - Components representing hook functionality should be placed in
example.stories.tsx
within__docs__
folder. In case file name will be missing.stories.tsx
part - code preview won't work.
4ex:src/useFirstMountState/__docs__/example.stories.tsx
. - Preferred format to write the docs is MDX. Read more about storybook docs.
- Docs should be placed in
- Add docs link and hook summary to the
README.md
. - After all above steps are done - run
yarn lint:fix
and ensure that everything is styled by our standards. - Command
yarn new-hook myAwesomeHook
will help you create proper file structure for new hook.
This repo uses semantic-release and
conventional commit messages so prefix your commits with fix:
,
feat:
, etc., if you want your changes to appear in
release notes.
Also, there is a script that helps to properly format commit message:
git add .
yarn commit
It will guide you through several prompts that will ease filling non-obvious and easy-to-forget parts.
There are git hooks set up with this project that are automatically enabled when you install dependencies. These hooks automatically test and validate your code and commit message. In most cases disabling these hooks is not recommended.