Skip to content

Commit 9e13cfb

Browse files
committed
Update Listener/AnyListener jsdoc
1 parent 584dd3a commit 9e13cfb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Components.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ export function ArrayField<
4040

4141
/**
4242
* Wrapper around useListener
43-
* Listen for changes on a form's field. Behaves like useState.
44-
* You shouldn't use this hook in large components, as it rerenders each time something changes. Use the wrapper <Listener /> instead.
43+
* Renders using the provided render function each time the provided field changes. When no render function is provided, the current field value will be rendered as a string.
4544
* @param form The form to listen on.
4645
* @param name The form's field to listen to.
4746
*/
@@ -57,8 +56,7 @@ export function Listener<
5756

5857
/**
5958
* Wrapper around useAnyListener.
60-
* Listens for any change on this form. Behaves like useState.
61-
* You shouldn't use this hook in large components, as it rerenders each time something changes. Use the wrapper <AnyListener /> instead.
59+
* Renders using the provided render function each time something in the form changes. When no render function is provided, a JSON representation of the form values is displayed.
6260
* @param form The form that was passed in.
6361
*/
6462
export function AnyListener<T extends object, State = DefaultState, Error extends DefaultError = DefaultError>(props: {

testing/src/Fieldform.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { useForm, Field, AnyListener, FieldError, FormField } from "typed-react-form";
2+
import { useForm, Field, AnyListener, FieldError, FormField, Listener } from "typed-react-form";
33

44
function Input(props: { value?: string; onChange?: (value: string) => void; style: React.CSSProperties }) {
55
return <input style={{ padding: "0.3em", ...props.style }} value={props.value} onChange={(ev) => props.onChange?.(ev.target.value)} />;
@@ -39,6 +39,9 @@ export function FieldForm() {
3939
<option value="male">male</option>
4040
<option value="female">female</option>
4141
</Field>
42+
<p>
43+
value: <Listener form={form} name="firstName" />
44+
</p>
4245
<pre>
4346
<AnyListener form={form} render={() => JSON.stringify(form.values, null, 2)} />
4447
</pre>

0 commit comments

Comments
 (0)