-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): handle React 18 batching for "Submit" button on details page. …
…Fixes #13453 (#13593) Signed-off-by: Mason Malone <[email protected]>
- Loading branch information
Showing
6 changed files
with
43 additions
and
43 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {useState} from 'react'; | ||
|
||
/** | ||
* useEditableObject is a React hook to manage the state of object that can be edited and updated. | ||
* Uses ref comparisons to determine whether the resource has been edited. | ||
*/ | ||
export function useEditableObject<T>(initial?: T): [T, boolean, React.Dispatch<T>, (value: T) => void] { | ||
const [value, setValue] = useState<T>(initial); | ||
const [initialValue, setInitialValue] = useState<T>(initial); | ||
|
||
// Note: This is a pure reference comparison instead of a deep comparison for performance | ||
// reasons, since <ObjectEditor> changes are latency-sensitive. | ||
const edited = value !== initialValue; | ||
|
||
function resetValue(value: T) { | ||
setValue(value); | ||
setInitialValue(value); | ||
} | ||
|
||
return [value, edited, setValue, resetValue]; | ||
} |
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