You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm facing an issue with a Select component in my react project. When I fetch options from an API and display them in the select component, the selected value only displays correctly if I select the option twice, also the initially selected value fetched from the backend does not show up.
Code:
<Selectvariant="standard"label="Current Living Address"name="current_address"value={values.current_address}onChange={(val)=>handleChange({target: {name: "current_address",value: val}})}onBlur={handleBlur}error={Boolean(errors.current_address&&touched.current_address)}>{addresses.length>0&&(addresses.map((address)=>(<Optionkey={address.id}value={address.id}className="capitalize">{address.number} - {address.street}</Option>)))}</Select>{errors.current_address&&touched.current_address&&(<ErrorTexterror={errors.current_address}/>)}
The text was updated successfully, but these errors were encountered:
Select component in controlled state will not work properly if the options are not available yet on initial render. Workaround is by making sure the options are readily available first, before rendering the Select component.
Or you can add a default option as suggested by their bot support:
I'm facing an issue with a
Select
component in my react project. When I fetch options from an API and display them in the select component, the selected value only displays correctly if I select the option twice, also the initially selected value fetched from the backend does not show up.Code:
The text was updated successfully, but these errors were encountered: