useNavigation hook return when a form submission is in progress?useNavigation to track navigation state. What is the value of navigation.state during a form submission?import { useNavigation } from '@remix-run/react'; export default function MyComponent() { const navigation = useNavigation(); return <div>{navigation.state}</div>; }
The useNavigation hook returns an object with a state property that can be idle, submitting, or loading. When a form is being submitted, the state is submitting.
navigation.state is "loading"?navigation.state is "loading"?import { useNavigation } from '@remix-run/react'; export default function LoadingIndicator() { const navigation = useNavigation(); return ( <div> {navigation.state === 'loading' ? <p>Loading...</p> : <p>Ready</p>} </div> ); }
The component checks if navigation.state equals "loading". If true, it renders "Loading..."; otherwise, it shows "Ready".
useNavigation to disable a submit button during form submission?The submit button should be disabled only when navigation.state is "submitting". Other states do not indicate active submission.
useNavigation:import { useNavigation } from '@remix-run/react'; export default function Loader() { const navigation = useNavigation(); if (navigation.state === 'loading') { return <p>Loading...</p>; } return <p>Done</p>; }
The if condition uses a single equals sign (=), which assigns 'loading' to navigation.state instead of comparing it. This causes a bug where the condition always evaluates to true but does not behave as expected.
navigation.state === 'submitting' and navigation.state === 'loading' in Remix's useNavigation hook?useNavigation.In Remix, navigation.state === 'submitting' indicates a form submission is in progress. navigation.state === 'loading' means the app is loading new data or a new route after navigation.
