Complete the code to import the hook that helps track navigation state.
import { [1] } from '@remix-run/react';
The useNavigation hook is imported from @remix-run/react to track navigation states like loading or submitting.
Complete the code to get the current navigation state inside a component.
const navigation = [1]();Calling useNavigation() inside a component returns the current navigation state object.
Fix the error in the conditional that checks if the navigation state is 'submitting'.
if (navigation.state === [1]) { return <p>Submitting...</p>; }
The navigation state to check when a form is being submitted is 'submitting'.
Fill both blanks to show a loading message when navigation is in progress.
if (navigation.state === [1] || navigation.state === [2]) { return <p>Loading...</p>; }
Navigation states 'loading' and 'submitting' both indicate a pending state where a loading message is appropriate.
Fill all three blanks to create a component that shows different messages based on navigation state.
function StatusMessage() {
const navigation = [1]();
if (navigation.state === [2]) {
return <p>Submitting form...</p>;
} else if (navigation.state === [3]) {
return <p>Loading page...</p>;
}
return <p>Ready</p>;
}The component uses useNavigation() to get the navigation state. It checks for 'submitting' to show a submitting message and 'loading' to show a loading message. Otherwise, it shows 'Ready'.
