Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-changed-props

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

use-changed-props

React Hook to output props that have changed

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
208
increased by21.64%
Maintainers
1
Weekly downloads
 
Created
Source

use-changed-props

A React hook to log which props have changed. The hook will also include the changes for each prop, which is useful for tracking down unnecessary work when nothing really changed eg. a reference was updated.

https://www.npmjs.com/package/use-changed-props

Demo

https://codepen.io/mozmorris/pen/BaopXRX?editors=1111

Installation

npm install use-changed-props

or

yarn add use-changed-props

Usage

Log changed props to console

import useChangedProps from "use-changed-props"

const App = props => {

  // log props changes
  useChangedProps(props)

  return </div>
}

Disable logging

import useChangedProps from "use-changed-props"

const App = props => {

  // disable logging
  const options = { log: false }

  // store changed props
  const changedProps = useChangedProps(props, options)

  return </div>
}

Options

OptionDescriptionDefault
logShould automatically log prop changes to the consoletrue

License

MIT

Motivation

"How to check what props have changed?"

"Determine which props caused a re-render"

I've found myself Googling these questions on more than one occasion. Ideally I can now just drop this hook in to my component and get feedback about which props have changed and also the differences.

Keywords

FAQs

Package last updated on 04 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc