Randy_Johnson's avatar

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
0 likes
4 replies
parthjani7's avatar
Level 2

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;
1 like
Randy_Johnson's avatar

@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.