Skip to content

<form.Subscribe> allows missing selector in types, but crashes at runtime (selector is not a function) #2063

@ShrJamal

Description

@ShrJamal

Describe the bug

form.Subscribe currently allows omitting selector at type level, but in runtime it passes undefined into useStore, which throws:

TypeError: selector is not a function

So there is no TypeScript warning, but the app crashes when rendering <form.Subscribe> without selector.

Your minimal, reproducible example

https://tanstack.com/form/latest/docs/examples/react/simple

Steps to reproduce

const form = useForm({
  defaultValues: { name: "" },
  onSubmit: async () => {},
})

return (
  <form.Subscribe>
    {(s) => <button disabled={s.isSubmitting}>Save</button>}
  </form.Subscribe>
)

Expected behavior

Either:

  • selector should be optional and default internally to identity ((state) => state), or
  • selector should be required in types so TS catches this at compile time.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

macOS

TanStack Form adapter

None

TanStack Form version

1.28.4

TypeScript version

5.9.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions