zaguiini / formik-wizard

A multi-step form component powered by formik and react-albus
MIT License
86 stars 26 forks source link

Pass the Formik render's method props to the step component. #6

Closed michelts closed 5 years ago

michelts commented 5 years ago

Hi Luis Felipe, how are you?

What do you think about pass the formik props to the step component?

This way, I would be able to conditionally show some fields based on the current form values.

For instance, if I have news entry post and a flag publishLater. When the flag is true, I would show a DateField component.

I could rely in the local state of the step component, but I prefer to hold the flag inside formik's state. This way, if the user advance and go back to previous step, the flags decisions are preserved.

I've started a merge request, but I didn't find tests in the lib, and I'm not familiar with type script yet, so I will need more time to finish :)

Anyway, before that, do you agree with this proposal?

zaguiini commented 5 years ago

Hey Michel, I’m doing fine, what about you?

You can currently do that using the connect HOC or useFormikContext hook. I’m not sure about adding multiple sources of truth, to be honest...

What can be done is to update the README to include this particular use case, which sounds like the best option for us. What do you think?

michelts commented 5 years ago

Sorry, my fault!

I use formik with the Formik component most part of the time, I didn't think in connect as an alternative for this case :smile:

Anyway, I can do it even with Field and children/render props, that way, I have access to the whole form values anyway.

<Field name="flag" ... />
<Field
  name="name"
  render={({ form: { values: { flag } } }) => (
    <input disabled={!flag} />
  )}
/>

I'm not sure if it deserves a section in the README. Do you think I can add this use case in the examples?

zaguiini commented 5 years ago

I think it's worth it, because what if someone else comes across the same issue in the future? Easier to see that on the README than in the closed PRs

michelts commented 5 years ago

You are right

I took another look at the Formik documentation, and, in the Formik component docs, there are samples showing the usage of the Formik component injected props like handleChange, handleBlur and values.

This way, any mention in the docs would be useful. I've created another pull request with a FAQ entry that must fit the case, can you check it?