Issue with react-select AsyncCreatableSelect does not show values with Formik #2954
-
I have created a codesandbox here: https://codesandbox.io/s/formik-codesandbox-template-forked-cte9o?file=/TestComponent.js When I make a selection, my Formik shows form value, but react-select does not. I'm not sure what I'm doing wrong here. If I change "opt.value" to "opt", it shows the name in the selection, but that's not working with "clear" action and it not what I want to show in the form field. Any help is appreciated, thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
We discussed this in another issue or discussion. AsyncCreatableSelect requires you pass the full option object. If you only pass |
Beta Was this translation helpful? Give feedback.
-
Thanks, @johnrom , I got an update for my issue, I had another deep look into this, and I found: I have checked this issue and the sandbox for it is https://codesandbox.io/s/react-select-formik-jet92?file=/src/Form.jsx. In this example, they are not using Then I made an updated sandbox of mine:
Though I have no idea why using a Field or not makes this difference... 🤔 But it's a kinda ugly workaround for myself. Thanks to the community! |
Beta Was this translation helpful? Give feedback.
-
@flora8984461 you'd need to either use There's a bit of redundancy in your sandbox, and if you clean out that redundancy hopefully it'll show how straightforward Formik's API can be: https://codesandbox.io/s/formik-asynccreatableselect-1-forked-0yrx0?file=/index.js |
Beta Was this translation helpful? Give feedback.
We discussed this in another issue or discussion. AsyncCreatableSelect requires you pass the full option object. If you only pass
opt.value
to Formik (I recommend doing this, but it's very hard to use with AsyncCreatableSelect), you then have to select the option that matches formik.values.yourValue and pass that option object to AsyncCreatableSelect. This isn't an issue with Formik, but with AsyncCreatableSelect.