Skip to content

Commit bf2642f

Browse files
committed
fix(react-form): default selector to identity in Subscribe component
When <form.Subscribe> is rendered without a selector prop, it crashes at runtime because useStore receives undefined as the selector: TypeError: selector is not a function The types already mark selector as optional, so the runtime behavior should match. This adds a default identity function ((state) => state) for the selector parameter in both LocalSubscribe implementations (useForm and useFieldGroup). Fixes #2063
1 parent a4e8dec commit bf2642f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/react-form/src/useFieldGroup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import type { LensFieldComponent } from './useField'
2323

2424
function LocalSubscribe({
2525
lens,
26-
selector,
26+
selector = (state) => state,
2727
children,
2828
}: PropsWithChildren<{
2929
lens: AnyFieldGroupApi
30-
selector: (state: FieldGroupState<any>) => FieldGroupState<any>
30+
selector?: (state: FieldGroupState<any>) => FieldGroupState<any>
3131
}>): ReturnType<FunctionComponent> {
3232
const data = useStore(lens.store, selector)
3333

packages/react-form/src/useForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ export type ReactFormExtendedApi<
139139

140140
function LocalSubscribe({
141141
form,
142-
selector,
142+
selector = (state) => state,
143143
children,
144144
}: PropsWithChildren<{
145145
form: AnyFormApi
146-
selector: (state: AnyFormState) => AnyFormState
146+
selector?: (state: AnyFormState) => AnyFormState
147147
}>): ReturnType<FunctionComponent> {
148148
const data = useStore(form.store, selector)
149149

0 commit comments

Comments
 (0)