I've developed a customized MUI select component in React and have integrated it multiple times within another component as shown:
customDropdown.js
import * as React from 'react';
import FormControl from '@mui/material/FormControl';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';
import Chip from '@mui/material/Chip';
import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline';
import ArrowCircleUpIcon from '@mui/icons-material/ArrowCircleUp';
import ArrowCircleDownIcon from '@mui/icons-material/ArrowCircleDown';
import { useLocation } from 'react-router-dom';
export default function CustomDropdown({ inputLabelId, dropdownId, dropdownValue1, dropdownLabel }) {
const [dropdownValue, setDropDownValue] = React.useState('');
const location = useLocation();
const handleChange = (event) => {
setDropDownValue(event.target.value);
};
React.useEffect(() => {
setDropDownValue(dropdownValue1);
}, [location, dropdownValue1])
return (
<FormControl sx={{ m: 1, minWidth: 220 }}>
<InputLabel id={inputLabelId}>{dropdownLabel}</InputLabel>
<Select id={dropdownId} value={dropdownValue} label={dropdownLabel} onChange={handleChange}>
<MenuItem value={-1}><Chip size="medium" icon={<ArrowCircleDownIcon />} label="Decreasing" color="error" /></MenuItem>
<MenuItem value={0}><Chip size="medium" icon={<CheckCircleOutlineIcon />} label="No Trend" color="primary" /></MenuItem>
<MenuItem value={1}><Chip size="medium" icon={<ArrowCircleUpIcon />} label="Increasing" color="success" /></MenuItem>
</Select>
</FormControl>
);
}
And I am invoking the above component from another component multiple times by providing different values for labelId, dropdownID, etc.,
MainComponent.js
import CustomDropdown from '../components/customDropdown.js';
<CustomDropdown inputLabelId="Lbl_Id1" dropdownId="Id1" dropdownValue1={firstSelect} dropdownLabel="First" />
<CustomDropdown inputLabelId="Lbl_Id2" dropdownId="Id2" dropdownValue1={secondSelect} dropdownLabel="Second" />
When trying to retrieve the values of firstSelect & secondSelect after altering the dropdown values, there seems to be no impact.
If anyone could guide me on how to obtain the values for each dropdown in MainComponent.js, it would be greatly appreciated.
Thank you,