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 7, 2022
1 parent 6985531 commit 783d65e
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 783d65e

Please sign in to comment.