Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100868942
useForceUpdate.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, 11:08
Size
897 B
Mime Type
text/x-java
Expires
Wed, Feb 5, 11:08 (2 d)
Engine
blob
Format
Raw Data
Handle
24040849
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
useForceUpdate.js
View Options
import
{
useReducer
}
from
'react'
;
/**
* Returns a function that triggers a component update. the hook equivalent to
* `this.forceUpdate()` in a class component. In most cases using a state value directly
* is preferable but may be required in some advanced usages of refs for interop or
* when direct DOM manipulation is required.
*
* ```ts
* const forceUpdate = useForceUpdate();
*
* const updateOnClick = useCallback(() => {
* forceUpdate()
* }, [forceUpdate])
*
* return <button type="button" onClick={updateOnClick}>Hi there</button>
* ```
*/
export
default
function
useForceUpdate
()
{
// The toggling state value is designed to defeat React optimizations for skipping
// updates when they are stricting equal to the last state value
var
_useReducer
=
useReducer
(
function
(
state
)
{
return
!
state
;
},
false
),
dispatch
=
_useReducer
[
1
];
return
dispatch
;
}
Event Timeline
Log In to Comment