Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
react-use-value-change
Advanced tools
$ npm install react-use-value-change --save
or
$ yarn add react-use-value-change
Quite often I find myself having complex useEffect to detect the state changes. This library helps to keep up state tracking.
It contains Three simplified methods:
useStringValueChange
useNumberValueChange
useBooleanValueChange
const [currentValue, {setValue, resetValue, resetToCurrentValue, resetToOriginalValue}, {equals, original}] = useStringValueChange("the initial value");
currentValue
is the string current valueoriginal
is immutable original value (until value is reset)equals
indicates if original === currentValue
setValue("new value")
will change the currentValue
, keeps original
and equals
is false if the new value is different form originalresetValue()
will reset original
to currentValue
and equals
to trueresetValue("something else")
will reset currentValue
and original
to "something else" and equals
to trueresetToCurrentValue()
will reset the original
to currentValue
and equals
to trueresetToOriginalValue()
will reset the currentValue
to original
and equals
to trueAll the other methods follows the same pattern.
The difference are with input listeners
useStringInputValueChange
accepts HTMLTextAreaElement | HTMLInputElement
useNumberInputValueChange
accepts HTMLInputElement (input type number)
useBooleanInputValueChange
accepts HTMLInputElement (checkbox or radio)
Those accept HTMLTextAreaElement | HTMLInputElement
as setters. Which means one has to call
setValue(value: HTMLInputElement)
instead of setValue(value: string)
(or boolean or number)
There is also an umbrella method for more complex logic: useValueChange
, which has to be approached carefully as it might trigger recursive rendering.
See useValueChange.test.ts how to use it.
When is used the initial value is immutable. One has to use the React useffect
to reset the value.
FAQs
React value change listener
The npm package react-use-value-change receives a total of 1 weekly downloads. As such, react-use-value-change popularity was classified as not popular.
We found that react-use-value-change demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.