Skip to content

Commit

Permalink
Guard against empty Navigation title
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Mar 4, 2022
1 parent 82c3f57 commit 8fafe7b
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ export default function useCreateNavigationMenu( clientId ) {
// a new navigation menu when the user completes the final step.
const create = useCallback(
async ( title = null, blocks = [] ) => {
// Guard against creating Navigations without a title.
// Note you can pass no title, but if one is passed it must be
// a string otherwise the title may end up being empty.
if ( title && typeof title !== 'string' ) {
setError(
'Invalid title supplied when creating Navigation Menu.'
);
setStatus( ERROR );
throw new Error(
`Value of supplied title argument was not a string.`
);
}

setStatus( PENDING );
setValue( null );
setError( null );
Expand Down

0 comments on commit 8fafe7b

Please sign in to comment.