Well, I made an autocomplete using the code below and tried to display its icon after selecting each item, but it didn't work!
import { useState } from 'react'
import { TextField,InputAdornment ,Autocomplete,Box} from '@mui/material';
import v1 from './v1.svg';
import v3 from './v2.svg';
import v4 from './v3.svg';
import v4 from './v4.svg';
function App() {
const [useicon ,setUseicon]=useState(v1);
const options=[
{'label':"تتر","icon":v1},
{'label':"بایننس",'icon':v2},
{'label':"بی اس دی",'icon':v3},
{'label':"دای",'icon':v4},
]
return (
<div>
<Autocomplete
options={options}
getOptionLabel={(option) => option.label}
onChange={(e,value)=>{setUseicon(value['icon'])}}
sx={{width:"300px"}}
renderOption={(props, option) => (
<Box component="li" {...props}>
<img src={option.icon} style={{width:"50px",height:"50px"}} alt={option.label} />
{option.label}
</Box>
)}
renderInput={(params) => (
<TextField
{...params}
inputProps={{
...params.inputProps,
startAdornment: <InputAdornment position='end'>
<img src={useicon} />
</InputAdornment> ,
}}
/>
)}
/>
</div>
)
}
export default App;
some notes:
1-All the imports were correct and there is no problem
2-In the same way, the icon is shown in the TextField Component.
3-If there is a typo, know that it was in this post and not in the program itself
Please help because it is very important for me.