Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make runtime agnostic/Support React Native #439

Merged
merged 3 commits into from
Sep 3, 2023
Merged

Conversation

crutchcorn
Copy link
Member

This PR aims to solve React Native support and make the code less runtime/UI reliant by removing all methods and types that utilized the DOM. This includes:

  • Removing APIForm.getFormProps()
  • Removing APIField.getInputProps()
  • Removing APIField.getChangeProps()
  • Changing APIForm.handleSubmit() to remove e argument
  • Adding a new APIField.handleChange() to call on an input by: onChange={e => field.handleChange(e.target.value)}
  • Adding a new APIField.handleBlur() to call on an input by: onBlur={field.handleBlur}

While this might seem like a more verbose syntax, it brings a few additional benifits:

  • Avoids headaches with typings for UI libraries like React Aria or ShadCN/UI that might not use exact input or similar under-the-hood.
  • Allows us more flexibility if UI libraries or runtimes have different props names
  • Reduces our API surface area, which makes cognitive load easier in the end
  • Detaches our implementation from React, which should be easier to adopt to other frameworks

@joaom00
Copy link
Contributor

joaom00 commented Sep 3, 2023

Do you think it would be worth adding a getInputProps to the adapters for quick setup? but keep handleChange, handleBlur to cover the cases listed in the topic.

@crutchcorn
Copy link
Member Author

@joaom00 I originally tried to implement this until I realized that we'd run into the same problem but for the React adapter. I'd rather not ship out different adapters for React / React Native.

I mean, we could theoretically do a useForm exported from @tanstack/react-form/dom but then there's still:

  • Confusion about API differences
  • More than one way to do a thing, making training harder

@crutchcorn crutchcorn merged commit eea47f0 into main Sep 3, 2023
5 checks passed
@crutchcorn crutchcorn deleted the make-runtime-agnostic branch September 3, 2023 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants