Skip to content

Commit

Permalink
Add navigateToScreen as dependency
Browse files Browse the repository at this point in the history
navigateToScreen should be added as the hook dependency, or hasEdits might not be the latest value when calling the function. In fact, due to the property of how hasEdits is updated, the navigateToScreen would always get the latest value of hasEdits, but it's best practice to add state and props that are used in the hook as its dependency, or it might get harder to develop new feature or maintain the code someday in the future.
  • Loading branch information
renintw committed Jun 9, 2023
1 parent f7e9790 commit b81b7d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions settings/src/components/revalidate-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import { refreshRecord } from '../utilities/common';
export default function RevalidateModal() {
const { navigateToScreen } = useContext( GlobalContext );

const goBack = useCallback( ( event ) => {
event.preventDefault();
navigateToScreen( 'account-status' );
}, [] );
const goBack = useCallback(
( event ) => {
event.preventDefault();
navigateToScreen( 'account-status' );
},
[ navigateToScreen ]
);

return (
<Modal
Expand Down
11 changes: 7 additions & 4 deletions settings/src/components/screen-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ export default function ScreenLink( { screen, anchorText, buttonStyle = false, a
classes.push( 'is-secondary' );
}

const onClick = useCallback( ( event ) => {
event.preventDefault();
navigateToScreen( screen );
}, [] );
const onClick = useCallback(
( event ) => {
event.preventDefault();
navigateToScreen( screen );
},
[ navigateToScreen ]
);

return (
<a
Expand Down

0 comments on commit b81b7d6

Please sign in to comment.