creativetimofficial / material-tailwind

@material-tailwind is an easy-to-use components library for Tailwind CSS and Material Design.
https://material-tailwind.com/
MIT License
3.51k stars 307 forks source link

Select Component not showing value when dynamically map #501

Open huzaifah-here opened 7 months ago

huzaifah-here commented 7 months ago

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>
FurkanSezal commented 7 months ago

Having exactly same issue

dsebesta commented 7 months ago

same as well

TechnoFynch commented 6 months ago

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

syihab-net commented 6 months ago

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} ))} )}

YuAnWu0000 commented 2 months ago

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