Closed westerandr closed 2 years ago
This resolves #5.
Thanks for your interest in this package,
Can you tell me why we should not set our default value like this 👇
const [selected, setSelected] = React.useState(1); //Where 1 is the default selected id
This also nullifies your Issue raised #5 , as state variable persists for each render.
Still, if there is something i dont understand , please elborate a bit (why we should use default value prop)
Hi sir,
So for example, in this component say I provide a list of objects.
[ { key: 1, value: 'Apples' }, { key: 2, value: 'Bananas' } ]
I am keeping track of global state, so if user pick 'Bananas', the state variable will stay selected as 'Bananas'.
But if I want to exit out of the page, and come back again. The state variable will still be 'Bananas' but the component won't show/render 'Bananas', instead it will show/render 'Select an Option' or whatever you suggested which was default selected id 1.
Hope that makes sense.
Yes it does make sense to me now, Thanks for elaborating,
I will approve this PR
Thank you very much sir for this awesome package.
Set default option of select list if defaultOption prop specified.