I’m working with the React Admin framework and encountering a challenge with the SelectInput component. I have a dropdown containing multiple choices, and I need to set one of them as the default based on the data I receive from my server.
<FormDataConsumer>
{({ formData, getSource, scopedFormData }) => {
console.log(scopedFormData);
console.log(options);
return (
<div style={{ display: "flex" }}>
<div className={styles.container}>
<SelectInput
source={getSource("category")}
onChange={(value) => handleChange(value)}
label="Category"
choices={options}
optionText="title"
optionValue="value"
record={scopedFormData}
inputText={displayText}
clearAlwaysVisible={true}
fullWidth
required
/>
</div>
</div>
);
}}
</FormDataConsumer>
How can I ensure that the SelectInput automatically chooses the correct value when the component is first rendered? The backend returns data, and I would like one of the options in the dropdown to be pre-selected according to that information.