1.0.179 • Published 22 hours ago

@jetplane/velocity-tools v1.0.179

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
22 hours ago

React Hooks to npm boilerplate

This repository is a boilerplate for creating custom React hooks and components that we can publish to NPM registry as packages.

I've put together a quick tutorial, it assumes an understanding of React, hooks and unit tests.

If something is not clear, message me or raise an issue, I will explain in more detail.

I've used this boilerplate to create my NPM package https://www.npmjs.com/package/@nekogd/react-utility-hooks.

First things first

Firstly, clone this repository.

Next, go over to package.json file and amend name, description and author keys.

The package would be served on npm as per what you have typed in the "name".

You may want to use scoped naming i.e. "@myscope/use-my-hook"

More info: https://docs.npmjs.com/using-npm/scope.html

How we will be able to use your package

It follows the common React path.

Follow through the included useCounter example and you will be fine.

Make sure to export your hook (I prefer named exports) in index.ts.

Basically you have to do three things:

a) write your hook (preferably test and type it)

b) export it in index.ts file

c) deploy to NPM

We will able to use your hook like so:

 import { useYourHook } from 'your-package-name'

Development commands

 // watch
 yarn start

 // or
 npm run start
 // builds the dist folder
 yarn build

 // or
 npm run build
 // starts tests
 yarn test

 // or

 npm run test

Local testing and yarn link

To locally test the package, do the following:

Let's assume your package name is "use-my-counter" and your CRA is "my-app".

Let's also assume they are in one workspace.

workspace
  - use-my-counter
  - my-app

a) in hook folder, run

yarn link

b) assuming you have a workspace, create a sample CRA app

npx create-react-app my-app

c) navigate to your CRA app folder

cd my-app

d) run command

 yarn link use-my-counter

e) In your CRA app, you can now user package, as it's linked locally

  import { useMyCounter } from 'use-my-counter';

f) However, this will give you an error due to different copy of React and in CRA app. To counter that let's assume that we have workspace

workspace
  - use-my-counter
  - my-app

We navigate to use-my-counter and type (this will link the React versions locally).

Please amend the path to your needs.

 npm link ../my-app/node_modules/react

We should be good to go to work locally.

Deployment to NPM

Login to correct NPM account

npm login

Versioning

Increase the version number as per NPM guides https://docs.npmjs.com/about-semantic-versioning.

// increases the first digit i.e. from 0.5.4 to 1.0.0
npm version major

// increases the second digit i.e. from 0.0.3 to 0.1.0
npm version minor

// increases the third digit i.e. from 0.0.1 to 0.0.2
npm version patch

Deployment

Run the command and the package should be up.

npm publish --access public

What If I want to export a component?

You can do that too, following same pattern as you'd with hooks.

Bear in mind you'd propably need .tsx file and not .ts.

Share with the world

Share your work and learnings with the world! :)

1.0.179

22 hours ago

1.0.177

2 days ago

1.0.176

11 days ago

1.0.175

11 days ago

1.0.174

11 days ago

1.0.173

11 days ago

1.0.172

13 days ago

1.0.169

15 days ago

1.0.171

15 days ago

1.0.170

15 days ago

1.0.165

17 days ago

1.0.164

17 days ago

1.0.167

17 days ago

1.0.166

17 days ago

1.0.161

17 days ago

1.0.160

17 days ago

1.0.162

17 days ago

1.0.168

17 days ago

1.0.159

17 days ago

1.0.158

27 days ago

1.0.157

27 days ago

1.0.154

28 days ago

1.0.153

28 days ago

1.0.156

28 days ago

1.0.155

28 days ago

1.0.151

1 month ago

1.0.149

1 month ago

1.0.150

1 month ago

1.0.147

1 month ago

1.0.146

1 month ago

1.0.148

1 month ago

1.0.145

2 months ago

1.0.143

2 months ago

1.0.142

2 months ago

1.0.144

2 months ago

1.0.141

2 months ago

1.0.140

2 months ago

1.0.139

2 months ago

1.0.136

2 months ago

1.0.135

2 months ago

1.0.138

2 months ago

1.0.137

2 months ago

1.0.134

2 months ago

1.0.133

2 months ago

1.0.132

2 months ago

1.0.131

3 months ago

1.0.130

5 months ago

1.0.129

5 months ago

1.0.128

5 months ago

1.0.127

6 months ago

1.0.126

6 months ago

1.0.125

6 months ago

1.0.124

6 months ago

1.0.123

6 months ago

1.0.122

6 months ago

1.0.121

6 months ago

1.0.120

6 months ago

1.0.119

6 months ago

1.0.118

6 months ago

1.0.117

6 months ago

1.0.116

6 months ago

1.0.115

6 months ago

1.0.114

6 months ago

1.0.112

6 months ago

1.0.111

6 months ago

1.0.110

6 months ago

1.0.109

6 months ago

1.0.108

6 months ago

1.0.107

6 months ago

1.0.106

6 months ago

1.0.105

6 months ago

1.0.104

6 months ago

1.0.103

6 months ago

1.0.102

6 months ago

1.0.101

6 months ago

1.0.100

6 months ago

1.0.99

6 months ago

1.0.98

6 months ago

1.0.97

6 months ago

1.0.96

6 months ago

1.0.95

6 months ago

1.0.94

6 months ago

1.0.93

6 months ago

1.0.92

6 months ago

1.0.91

6 months ago

1.0.90

6 months ago

1.0.89

6 months ago

1.0.88

6 months ago

1.0.87

6 months ago

1.0.86

6 months ago

1.0.85

6 months ago

1.0.84

6 months ago

1.0.83

6 months ago

1.0.81

6 months ago

1.0.80

7 months ago

1.0.79

7 months ago

1.0.78

7 months ago

1.0.77

7 months ago

1.0.76

8 months ago

1.0.75

8 months ago

1.0.73

8 months ago

1.0.72

8 months ago

1.0.71

8 months ago

1.0.70

8 months ago

1.0.69

8 months ago

1.0.68

8 months ago

1.0.67

8 months ago

1.0.66

8 months ago

1.0.65

8 months ago

1.0.64

8 months ago

1.0.63

8 months ago

1.0.62

8 months ago

1.0.61

9 months ago

1.0.60

9 months ago

1.0.59

9 months ago

1.0.58

9 months ago

1.0.57

9 months ago

1.0.56

9 months ago

1.0.55

9 months ago

1.0.54

9 months ago

1.0.53

9 months ago

1.0.52

9 months ago

1.0.51

9 months ago

1.0.50

9 months ago

1.0.49

9 months ago

1.0.48

9 months ago

1.0.47

9 months ago

1.0.46

9 months ago

1.0.45

9 months ago

1.0.44

9 months ago

1.0.43

9 months ago

1.0.42

9 months ago