Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100846482
usePrevious.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 3, 05:53
Size
607 B
Mime Type
text/x-java
Expires
Wed, Feb 5, 05:53 (2 d)
Engine
blob
Format
Raw Data
Handle
24041044
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
usePrevious.js
View Options
import
{
useEffect
,
useRef
}
from
'react'
;
/**
* Store the last of some value. Tracked via a `Ref` only updating it
* after the component renders.
*
* Helpful if you need to compare a prop value to it's previous value during render.
*
* ```ts
* function Component(props) {
* const lastProps = usePrevious(props)
*
* if (lastProps.foo !== props.foo)
* resetValueFromProps(props.foo)
* }
* ```
*
* @param value the value to track
*/
export
default
function
usePrevious
(
value
)
{
var
ref
=
useRef
(
null
);
useEffect
(
function
()
{
ref
.
current
=
value
;
});
return
ref
.
current
;
}
Event Timeline
Log In to Comment