-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web] Update button label after successful copy
Summary: Change button label after successful action. Depends on D8246 Test Plan: Click copy button and check if the label changes. Click it repeatedly and check if the label changes back only after 2s. from the last click. Click it and close modal - nothing should break. Reviewers: bartek, kamil, inka Reviewed By: kamil Subscribers: ashoat Differential Revision: https://phab.comm.dev/D8294
- Loading branch information
Showing
3 changed files
with
45 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// @flow | ||
|
||
import _debounce from 'lodash/debounce.js'; | ||
import * as React from 'react'; | ||
|
||
import type { SetState } from '../types/hook-types.js'; | ||
|
||
function useResettingState<T>( | ||
initialState: (() => T) | T, | ||
duration: number, | ||
): [T, SetState<T>] { | ||
const [value, setValue] = React.useState(initialState); | ||
const resetStatusAfterTimeout = React.useRef( | ||
_debounce(() => setValue(initialState), duration), | ||
); | ||
React.useEffect(() => resetStatusAfterTimeout.current.cancel, []); | ||
|
||
const setNewValue = React.useCallback((newValue: (T => T) | T) => { | ||
setValue(newValue); | ||
resetStatusAfterTimeout.current(); | ||
}, []); | ||
|
||
return React.useMemo(() => [value, setNewValue], [setNewValue, value]); | ||
} | ||
|
||
export { useResettingState }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters