Skip to content

form.Subscribe API inconsistency: children prop vs JSX children #1976

@Criezc

Description

@Criezc

Describe the bug

form.Subscribe doesn't accept children as a prop attribute, only as JSX children, but the examples given showing that it accept children as props.

When using form.Subscribe with a selector prop, passing the render function via the children prop attribute doesn't work. The component only works when the render function is passed as JSX children (between opening and closing tags).

This creates an inconsistency with other form components like form.AppField, which accept children as a prop attribute.

Eventually both pattern works as expected but typescript complaining about the error.

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-of4hmkxe?file=src%2FApp.tsx

Steps to reproduce

  1. Create a form using withForm or useForm
  2. Use form.Subscribe with a selector prop
  3. Pass the render function via the children prop attribute
<form.Subscribe
  children={(title) => {
    return <div>{title}</div>
  }}
  selector={(state) => state.values.title}
/>

Expected behavior

The form.Subscribe component should accept the render function via the children prop attribute, similar to how form.AppField works:

// This pattern should work (but currently doesn't)
<form.Subscribe
  children={(title) => <div>{title}</div>}
  selector={(state) => state.values.title}
/>

// This pattern works for form.AppField
<form.AppField
  children={(field) => <input {...field} />}
  name="title"
/>

How often does this bug happen?

Every time

Screenshots or Videos

Selector error:

Image

Props error:

Image

Platform

  • OS: Mac OS
  • Version: Sequoia 15.5

TanStack Form adapter

react-form

TanStack Form version

^1.27.7

TypeScript version

^5.7.2

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions