Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@murden.dev/lifecycle-hooks

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@murden.dev/lifecycle-hooks - npm Package Compare versions

Comparing version
0.0.1
to
1.0.0
+2
-2
package.json
{
"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": {

@@ -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
})
// (...)
}
```

@@ -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'

@@ -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])
)
}

@@ -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])
)
}

@@ -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