Skip to content

Commit

Permalink
docs: @location-state/confrom docs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akfm.sato authored and akfm.sato committed Apr 23, 2024
1 parent 6aed47e commit 6955f4d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/location-state-conform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
[![npm version](https://badge.fury.io/js/@location-state%2Fconform.svg)](https://badge.fury.io/js/@location-state%2Fconform)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Synchronize `conform` with history entries.
Synchronize [conform](https://conform.guide/) with history entries.

## Features

- Manage [conform](https://conform.guide/) state to synchronize with the history location.
- Manage conform state to synchronize with the history location.
- By default, supports Session Storage and URL as persistent destinations.

## Packages
Expand Down Expand Up @@ -90,7 +90,7 @@ export default function UserForm() {
});

return (
// use `getLocationFormProps` to get the form props
// Use `getLocationFormProps` to get the form props
<form {...getLocationFormProps(form)} action={action} noValidate>
<label htmlFor={fields.firstName.id}>First name</label>
<input
Expand Down
77 changes: 74 additions & 3 deletions packages/location-state-conform/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,96 @@

- [Form hooks](#Form-hooks)
- [function `useLocationForm`](#function-useLocationForm)
- [type `GetLocationFormProps`](#type-GetLocationFormProps)

## Form hooks

Form hooks that are used to manage the state of a form created with conform.
Form hooks that are used to manage the state of a form implemented with conform.

### function `useLocationForm`

```ts
export declare function useLocationForm<Schema extends Record<string, unknown>>({ location, idPrefix, }: Pretty<{
declare function useLocationForm<Schema extends Record<string, unknown>>({ location, idPrefix, }: {
location: {
name: string;
storeName: "session" | "url";
refine?: Refine<T>;
};
idPrefix?: string;
}>): [
}): [
{
id: string;
},
GetLocationFormProps
];
```

Returns a conform options and function to get form props.

#### Type Parameters

- `Schema`: The schema of the form.

#### Parameters

- `location`: Partial options of `LocationStateDefinition` from `@location-state/core`. View the more detail in the [API docs](/packages/location-state-core/docs/API.md).
- `name`: The name of the form.
- `storeName`: The store name of the form. It can be `session` or `url`.
- `refine`: The refine function of the form.
- `idPrefix`: The prefix of the form id.

#### Returns

Returns an array that first element is the conform options and the second element is the function to get form props.

#### Example

```tsx
const [formOptions, getLocationFormProps] = useLocationForm({
location: {
name: "your-form",
storeName: "session",
},
});

const [form, fields] = useForm({
lastResult,
onValidate({ formData }) {
return parseWithZod(formData, { schema: User });
},
...formOptions,
});

return (
<form {...getLocationFormProps(form)} action={action} noValidate>
...
</form>
);
```

### type `GetLocationFormProps`

```ts
// import { getFormProps } from "@conform-to/react";
type GetFormPropsArgs = Parameters<typeof getFormProps>;
type GetLocationFormPropsReturnWith = ReturnType<typeof getFormProps>;
type GetLocationFormProps = (
form: GetFormPropsArgs[0]
) => GetLocationFormPropsReturnWith & {
onChange: (e: React.ChangeEvent<HTMLFormElement>) => void;
};
```

The function to get form props. It extends the [`getFormProps`](https://conform.guide/api/react/getFormProps) function from the `@conform-to/react` package.

#### Parameters

- `form`: The form object that is returned from the `useForm` hook.

#### Example

```tsx
<form {...getLocationFormProps(form)} action={action} noValidate>
...
</form>
```

0 comments on commit 6955f4d

Please sign in to comment.