How to create a customized React hook package and publish it to npm?
Published in
5 min readJan 24, 2021
Introduction
There are several ways to share stateful logic between React components like render props and HOC (High Order Component). React hook provides a new option after v16.8.0. The main advantage of React hooks is that they can be uses as life cycle functions for function components.
I create my customized React hook when learning to React hook. This article is a note for people who also intend to create their own React hook package for npm.
There are a few topics in this article
- Development environment setting
- Customized hook
- Publish the package to npm
Development environment setting
1. Initial the project
- Type the following command in the terminal to generate the empty package.json
npm init
- Install packages for React
npm install -S react…