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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(solid): Added instructions with the use directive for solid. #292

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Blankeos
Copy link

@Blankeos Blankeos commented May 1, 2024

There was a weird "gotcha" that took me actually a few frustrating hours to figure out because it wasn't reflected in the docs or anything.

I'm not sure if use:form is actually possible because after some experimenting + reading up on how this works: https://docs.solidjs.com/reference/jsx-attributes/use#use.

I still couldn't get it. So I honestly don't know if it's a skill issue or just the docs.

This was the issue I posted yesterday: #291. I think adding this to the readme would save a ton of time.

I found two ways actually:

Fix 1: Defining in a global dts

// vite-env.d.ts (or any *.d.ts file)
declare global {
  declare module "solid-js" {
    namespace JSX {
      interface Directives {
        form: (node: HTMLFormElement) => void;
      }
    }
  }
}

image

Fix 2: Defining in local file where its used.

import { createForm } from "@felte/solid";

declare module "solid-js" {
  namespace JSX {
    interface Directives {
      form: (node: HTMLFormElement) => void;
    }
  }
}
export default function Register() {
  const { form } = createForm({
    onSubmit: async (values) => {
      /** call to an api. */
    },
  });

  return (
    <main class="text-center mx-auto text-gray-700 p-4">
      <h1 class="">Register</h1>

      <form class="form-control" use:form={form}>
      // ...

馃檨 Didn't work

I assumed just using use:form would work, but it didn't lol.

image

馃檨 Another attempt that didn't work.

This was what the docs showed, and it didn't work. (it's because of the global value)

// vite-env.d.ts (or any *.d.ts file)
declare module "solid-js" {
  namespace JSX {
    interface Directives {
      form: (node: HTMLFormElement) => void;
    }
  }
}

Copy link

vercel bot commented May 1, 2024

@Blankeos is attempting to deploy a commit to the Pablo Alejandro Berganza Campos' projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

None yet

1 participant