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

[Question] Render props pattern #202

Open
binajmen opened this issue Apr 25, 2024 · 2 comments
Open

[Question] Render props pattern #202

binajmen opened this issue Apr 25, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@binajmen
Copy link

I'm trying to apply some kind or render props pattern around modular-forms, without success :/

The general idea is: I have many kind of criteria, the only difference is the params. all the other fields are the same. To avoid repetition (I might end up with 10+ forms with the same logic except for params), I was trying to extract the common part of the form, so every pages for every criteria only have to specify the params part. Something like this:

      <CriterionForm<typeof paramsSchema> paramsSchema={paramsSchema}>
        {(form, Field) => (
          <Field name="params">
            {(field, props) => (
              <Params
                value={field.value}
                onChange={(value: ParamValue) =>
                  setValue(form, field.name, value)
                }
              />
            )}
          </Field>
        )}
      </CriterionForm>

I'm "nearly" there, but not there neither (TS mess) 🙈

Is there a TS wizard to help me here? 🙏

https://stackblitz.com/edit/modular-forms-render-props?file=src%2FApp.tsx,src%2F_form.tsx

(I asked the question on Discord but I'm afraid it will get lost rapidly)

@fabian-hiller fabian-hiller self-assigned this Apr 26, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Apr 26, 2024
@fabian-hiller
Copy link
Owner

Have you been able to resolve this issue or should I take a look at it?

@binajmen
Copy link
Author

binajmen commented May 2, 2024

I changed my approach as I was not able to solve this the way I wanted.
Don't spend too much time on this — especially if you're in the process of a rewrite, unless you think this is a valid use case.
Feel free to close the ticket depending on your decision ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants