JedWatson / react-select

The Select Component for React.js
https://react-select.com/
MIT License
27.42k stars 4.1k forks source link

not showing the inital value #5888

Open Mujtabaomar111 opened 3 months ago

Mujtabaomar111 commented 3 months ago

<Select styles={selectStyles} id='document_type' name='document_type' placeholder='---' isClearable onBlur={formik.handleBlur} value={document_type?.find( (option) => option.id.toString() === formik.values.document_type )} options={document_type?.map((mapRow) => ({ id: mapRow.id, name: mapRow.name_da, }))} getOptionLabel={(option) => option.name} getOptionValue={(option) => option.id} onChange={(selectedOption) => { formik.setFieldValue('document_type', selectedOption ? selectedOption.id : '') }} /> this is my code i have set the inital value to formik and the inital value is an id from douments type but react select doesnt show to name of selected value but simple select option do it, the second problem is that if i reset the from values, the values are cleaning but lables still keeps in Select option

resthomas commented 2 months ago

use defaultValue instead of value

iamamjad commented 1 month ago

if you're using next js 13 then also add the key props. e.g <Select defaultValue={selectedExaminersListFinal''} isMulti name="examiners" options={examinerusers} key={examinerusers} onChange={handleChangeExaminer} className="mt-1 block w-full" classNamePrefix="select" />