material-tailwind icon indicating copy to clipboard operation
material-tailwind copied to clipboard

Select Component not showing value when dynamically map

Open huzaifah-here opened this issue 2 years ago • 6 comments

image

Hi, I'm mapping value from api. But It is not appearing. When I click on create button Its saving the value which already i mapped. It just showing blank but the functionality is working

<div>{apiTeamIdGetResponse?.data?.driver1?.name}</div>
          <Select
            label="Driver 1"
            value={apiTeamIdGetResponse?.data?.driver1?.name}
            onChange={(selectedDriver) => {
              console.log(selectedDriver);
              setFormTeam({ ...formTeam, driver1Id: selectedDriver });
            }}
          >
            {apiDriverGetResponse?.data ? (
              // Render the options if apiDriverGetResponse.data is truthy
              apiDriverGetResponse?.data?.map((driver) => (
                <Option key={driver.id} value={driver.id}>
                  {driver.name}
                </Option>
              ))
            ) : (
              // Render a default option or placeholder if apiDriverGetResponse.data is falsy
              <Option key="default" value="default">
                No drivers available
              </Option>
            )}
          </Select>

huzaifah-here avatar Nov 13 '23 14:11 huzaifah-here

Having exactly same issue

FurkanSezal avatar Nov 13 '23 17:11 FurkanSezal

same as well

dsebesta avatar Nov 15 '23 05:11 dsebesta

I'm having the same issue. Has anyone found a workaround or solution? Using material-tailwind/react version 2.1.4

TechnoFynch avatar Dec 11 '23 06:12 TechnoFynch

I found a solution like this when using dynamic data. I have to rerender the select component again

{data.length > 0 && ( <Select label={label} value={value} onChange={ (val) => setData([]); fetchData(val) setValue(val) } error={!!error} disabled={disabled} > {data.map(({ id, value }, key) => ( <Option value={id} key={key} > {value} </Option> ))} </Select> )}

syihab-net avatar Dec 24 '23 07:12 syihab-net

Same here. I think the problem is Select is not mapping the Option with value but index now. I opened another issue for this: https://github.com/creativetimofficial/material-tailwind/issues/675

YuAnWu0000 avatar Apr 29 '24 03:04 YuAnWu0000