@murden.dev/lifecycle-hooks
Advanced tools
+2
-2
| { | ||
| "name": "@murden.dev/lifecycle-hooks", | ||
| "description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).", | ||
| "version": "0.0.1", | ||
| "description": "React Class Components lifecycle methods written as React Hooks for those that are transitioning from React Class Components or maybe just want a little more legibility in their code.", | ||
| "version": "1.0.0", | ||
| "main": "index.js", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
+32
-2
@@ -1,3 +0,33 @@ | ||
| # Use Lifecycle Hooks | ||
| # @murden.dev/lifecycle-hooks | ||
| For those that are transitioning from React Class Components or maybe just want a little more legibility in their code: `use-lifecycle-hooks` | ||
| ## React Class Components lifecycle methods written as React Hooks | ||
| For those that are transitioning from React Class Components or maybe just want a little more legibility in their code. | ||
| ### 1. Install package | ||
| `npm install @murden.dev/lifecycle-hooks` | ||
| ### 2. Import package and enjoy lifecycle-hooks :) | ||
| ```js | ||
| import { useOnMount, useOnUnmount, useOnUpdate } from '@murden.dev/lifecycle-hooks' | ||
| const Component = () => { | ||
| useOnMount(() => { | ||
| // Function that runs only once, when Component is mounted | ||
| }) | ||
| useOnUnmount(() => { | ||
| // Function that runs only once, when Component is about to be unmounted | ||
| }) | ||
| useOnUpdate(() => { | ||
| // Function that runs on every Component re-render | ||
| }) | ||
| // (...) | ||
| } | ||
| ``` |
+3
-3
@@ -1,3 +0,3 @@ | ||
| export { default as onMount } from './onMount' | ||
| export { default as onUnmount } from './onUnmount' | ||
| export { default as onUpdate } from './onUpdate' | ||
| export { default as useOnMount } from './onMount' | ||
| export { default as useOnUnmount } from './onUnmount' | ||
| export { default as useOnUpdate } from './onUpdate' |
+1
-2
@@ -6,6 +6,5 @@ import { useEffect } from 'react' | ||
| useEffect(() => { | ||
| console.log("Hey I just MOUNTED") | ||
| callback() | ||
| }, [callback]) // Empty array to run callback once; on mount. | ||
| }, [callback]) | ||
| ) | ||
| } |
+1
-2
@@ -7,7 +7,6 @@ import { useEffect } from 'react' | ||
| return () => { | ||
| console.log("Hey I'm about to UNMOUNT") | ||
| callback() | ||
| } | ||
| }, [callback]) // Empty array to run callback once; only on cleanup (unmount). | ||
| }, [callback]) | ||
| ) | ||
| } |
+1
-2
@@ -6,6 +6,5 @@ import { useEffect } from 'react' | ||
| useEffect(() => { | ||
| console.log("Hey I just UPDATED") | ||
| callback() | ||
| }) // Optional argument of an [] is not present. Will trigger on every re-render | ||
| }) | ||
| ) | ||
| } |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
-50%33
1000%2235
-43.67%6
-14.29%25
-10.71%