useFormSSR
useFormSSR(
form):void
Defined in: hooks.ts:32
Prepare the form for server-side rendering
Parameters
Section titled “Parameters”Form<any>
Form instance
Returns
Section titled “Returns”void
Remarks
Section titled “Remarks”Makes what the server renders agree with the client render that hydrates it:
- Element ids: assigns React's
useId()to the form's Form.stableId, which the stable ids of its fields build on. On unmount, it gives the form its own id back, unless something else has assigned another in the meantime, so a form that outlives the component doesn't keep an id tied to it.
Call it at the top of each component that renders a form, before any bind* call.
It covers that form only: a sub-form rendered by its own component calls it for itself,
so no component has to know what its ancestors did.
Harmless in a client-rendered app, so shared components can call it unconditionally. Anything it takes care of in the future has to keep it that way.
Example
Section titled “Example”const AddressForm: React.FC<{ model: PostalAddress }> = observer(({ model }) => { const form = Form.get(model); useFormSSR(form); return (...);});