[Select] Component not displaying the value on the first mount
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
When using the Select component it does not displaying the value on the first mount after data is receive from API
Expected Behavior 🤔
Render the value on the first mount like the other component (textfield) after data is receive from API
Steps to Reproduce 🕹
Here is my code
const [pile, setPile] = useState([]);
//Fetch
useEffect(() => {
if (open) {
const pileRequest = axios.get(`${process.env.REACT_APP_API_URL}/pile/${idPile}`);
const typeRequest = axios.get(`${process.env.REACT_APP_API_URL}/type/name`);
Promise.all([pileRequest, typeRequest])
.then((result) => {
setPile(result[0].data);
setType(result[1].data);
}).catch((err) => {
console.log(err);
});
}
}, [open]);
***
// Select
<FormControl fullWidth margin="normal">
<InputLabel>Type</InputLabel>
<Select label="Type" onChange={handleChangeType} value={pile.type}>
<MenuItem value={0}>Board</MenuItem>
<MenuItem value={1}>Panel</MenuItem>
</Select>
</FormControl>
Context 🔦
I want to display the values from my API with pre-filled fields
Your Environment 🌎
`npx @mui/envinfo`
System:
OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
Binaries:
Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
Yarn: Not Found
npm: 7.23.0 - ~/.nvm/versions/node/v14.17.6/bin/npm
Browsers:
Chrome: Not Found
Firefox: Not Found
npmPackages:
@emotion/react: ^11.4.1 => 11.4.1
@emotion/styled: ^11.3.0 => 11.3.0
@mui/core: 5.0.0-alpha.49
@mui/icons-material: ^5.0.1 => 5.0.1
@mui/lab: ^5.0.0-alpha.48 => 5.0.0-alpha.49
@mui/material: ^5.0.1 => 5.0.2
@mui/private-theming: 5.0.1
@mui/styled-engine: 5.0.1
@mui/styles: ^5.0.1 => 5.0.1
@mui/system: 5.0.2
@mui/types: 7.0.0
@mui/utils: 5.0.1
@types/react: 17.0.24
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
typescript: 4.4.3
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
React-select does not show the selected value in the field
The values when selected are stored in the state via portfolioSelector function. The problem is that when i select a value it wasn't...
Read more >Selected value not showing in the input field [Controlled ...
Same issue here. The workaround works but it is a lot of code for a simple select component with a few elements in...
Read more >API - React Select
The statemanager is a utility class that wraps around the base Select and each Select variant to expose inputValue and value as controllable...
Read more >React.Component
React lets you define components as classes or functions. ... extra re-rendering which, while not visible to the user, can affect the component...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@MGMehdi the issue this your are using
const [pile, setPile] = useState([]);
as an array and passing to selectpile.type
in this case type is undefined. So that’s why value is not showing. try to change state likeIt doesn’t look like this bug report has enough info for one of us to reproduce it.
Please provide a CodeSandbox (https://material-ui.com/r/issue-template-latest), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem.
Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve