Form navigation state #4555
Replies: 4 comments 6 replies
-
Ahh! I've been thinking of this too. Little values to identify a form submission that you don't want to actually go in the I've also wondered about let [Form, { formData }] = useForm();
// normal form API
<Form />
// but `formData` is only populated when *this form* is being submitted |
Beta Was this translation helpful? Give feedback.
-
I’m not familiar with this pattern. Would you mind helping me understand with an example of how people normally use this to build optimistic UI? 🙏 |
Beta Was this translation helpful? Give feedback.
-
An example: AddToCartButton -> sends CartDrawer -> To optimistically render this new line item, we need more than the Since the mutation can be initiated from a collection or or a product page, we have no way to get this additional product info. So, we have to pass them also as hidden inputs, so we can capture them in the CartDrawer via |
Beta Was this translation helpful? Give feedback.
-
Maybe somewhat tangentially related but would we be open to exposing the navigation
async function action({ request, state }) {
await process(state.complexObject)
return { ok: true }
}
function Component() {
let complexObject = useDataFromSomewhere();
return (
<Form state={{ complexObject }}>
<button type="submit">Submit</button>
</Form>
);
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
A pattern that exists today for optimistic UI's consists of using hidden inputs to gain access to data only needed client side. If we could introduce a "state" concept for form submissions, or piggy back on the router state, we could remove unnecessary fields from being serialized over the network.
Something like:
Beta Was this translation helpful? Give feedback.
All reactions