top | item 36514526

UseChildFormStatus a wrapper for useFormStatus (React 18.3)

1 points| jlarky2012 | 2 years ago |gist.github.com

1 comment

order

jlarky2012|2 years ago

I wrote this. React Experimental has added `useFormStatus` hook, which might be unintuitive if you are coming to this from something like Remix where you use something like this:

const navigation = useNavigation(); // navigation.state === "submitting"

that code works in a "global" scope, but useFormStatus only works if your component is a child of the form you want to get the status for. In practical terms, this means that you can create, say, a submit button component and use it there, but you can't easily use that state higher up, for example, if you want to add class to a pending form.

This is a pretty simple utility that will give you more control over where that state can be accessed