React JS Values not displaying in select
Values not displaying in select box. Values are shown that they are being passed when I console.log.
const SelectBox = (props) => {
return (
<>
<select>
<option selected>Open this select menu</option>
{props.students.forEach((student) => {
<option value="{student.id}">{student.name}</option>
})}
</select>
</>
)
}
export default SelectBox
use map()
const SelectBox = (props) => {
return (
<select>
<option selected>Open this select menu</option>
{props.students.map((student) => (
<option value={student.id}>{student.name}</option>
))}
</select>
);
};
export default SelectBox;
@parthjani7 Thanks for helping, but I was missing the return.
<>
<select>
<option selected>Open this select menu</option>
{props.students.map((student) => {
return (<option value="{student.id}">{student.name}</option>);
})}
</select>
</>
Please or to participate in this conversation.