Open Gugarauj07 opened 12 months ago
you can use defaultOption
you can use
defaultOption
export default function App() {
const [selected, setSelected] = useState([]);
const data = [
{key:'1',value:'Jammu & Kashmir'},
{key:'2',value:'Gujrat'},
{key:'3',value:'Maharashtra'},
{key:'4',value:'Goa'},
]
return(
<MultipleSelectList
setSelected={(val) => setSelected(val)}
data={data}
save="value"
onSelect={() => alert(selected)}
label="Categories"
defaultOption={{ key:'1', value:'Jammu & Kashmir' }} //default selected option
/>
)
}
I tryed using it like this, but there is no default variable selected.
you can use
defaultOption
export default function App() { const [selected, setSelected] = useState([]); const data = [ {key:'1',value:'Jammu & Kashmir'}, {key:'2',value:'Gujrat'}, {key:'3',value:'Maharashtra'}, {key:'4',value:'Goa'}, ] return( <MultipleSelectList setSelected={(val) => setSelected(val)} data={data} save="value" onSelect={() => alert(selected)} label="Categories" defaultOption={{ key:'1', value:'Jammu & Kashmir' }} //default selected option /> ) }
I tryed using it like this, but there is no default variable selected.
yeah, me too
In my case adding defaultOption
makes it unable to change value onSelect.
Same for me. When a checkbox is ticked, I assume it is stored in a state? The documentation details the properties of setSelected but not the state. Is there a possibility to have multiple default selected values? I can collaborate on that
i have same issue. the option is not selected.
edit: nevermind i got it working, defaultOption={{key: text, value: text}}
In my profile page, i want to display in the dropdown the previously variables selected by the user.