Closed ninjasun closed 2 years ago
Hi there @ninjasun! 👋
For resetting uncontrolled components (like MultiSelect
), you could use key
. The "You Probably Don't Need Derived State" post talks about this approach over in: https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html#recommendation-fully-uncontrolled-component-with-a-key
In practice, this would allow you to reset the state of the MultiSelect without having to control it's state.
Hope this helps!
thank @joshblack very appreciated. I made it work and I learned a new thing.
However, I think there should be a proper way to control it. like a prop. thanks again for the quick solution :)
Package
carbon-components-react
Browser
Chrome
Package version
7.40.1
Description
I am expecting to be able to control the component via props.
The reset button should clean the multiselect.
Also tested with 7.46.0
CodeSandbox example
https://codesandbox.io/s/carbon-components-react-forked-9mxge?file=/src/index.js
Steps to reproduce
select some items and click reset
Code of Conduct