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

Add Solid JS support #24

Merged
merged 4 commits into from
Jan 4, 2024
Merged

Conversation

dsnjunior
Copy link
Contributor

Changes

  • Add a solid-js form template
  • Update CLI to prompt for solid-js
  • Add a solid-js test to examples/form

Copy link

changeset-bot bot commented Jan 3, 2024

🦋 Changeset detected

Latest commit: 1a6ee1e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@examples/playground Patch
simple-stack-form Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Owner

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit on the use of Show, but this is a pretty solid PR 👏

}

return (
<Show when={fieldState()}>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need this Show check if we're throwing above? We could also remove the function wrapper on fieldState without this check I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but if I do this, it says it can be undefined 😭

image

Should I add the !?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if I do this, it loses reactivity

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have other ideas? I could change the tsconfig for this template to strict instead of strictest and it will work in this approach

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh thanks, I see the issue now. I'd like to keep strictest since this will be generated code in the user's project, and I want to pass the strictest config possible to ensure we don't raise type errors in your project.

I figured out the problem though! We need to hoist the state inside the state function. That way it can guarantee the function never returns undefined, since it's always mapped to an error. The solution you showed above does not guarantee that. You can check fieldState() !== undefined, but what if calling that function a second time returns a different value? TypeScript unfortunately isn't smart enough to see that.
image

sanitizeFormResult
].forEach((formResult) => {
if (formResult?.data) {
console.log(formResult.data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor!

examples/playground/src/components/solid-js/Form.tsx Outdated Show resolved Hide resolved
@bholmesdev bholmesdev merged commit 1248f72 into bholmesdev:main Jan 4, 2024
1 check passed
This was referenced Jan 4, 2024
@dsnjunior dsnjunior deleted the add-solid-js-support branch January 4, 2024 03:05
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.

2 participants