Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Emokores's avatar

Cannot show selected value from <Select /> element in React with Inertia

I have an edit form on Edit.js that retrieves data from the database. However, the <Select /> element does not show the selected value. This component works fine elsewhere in my project, but on this particular form on the Edit.js page, it's failing. I need the second pair of eyes on this. This is the structure for the component:


export default function Select({id, name, onChange, className, options, value, placeholder, required,}) {
    return (
        <>
            <select
                className={
                    `border-gray-300 focus:border-indigo-200 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-xl shadow-sm sm:text-sm` +
                    className
                }
                name={name}
                required={required}
                id={id}
                onChange={onChange}
                value={value}
            >
                <option>{placeholder}</option>
                {options.map((option, index) => {
                    return (
                        <option key={index} value={option.value}>
                            {option.label}
                        </option>
                    );
                })}
            </select>
        </>
    );
}

This is what I have on the frontend Edit.js page:


const {data, setData} = useForm({
       gender: user.gender
})

<form>
      <Select value={data.gender} onChange={handleChange} options={genderSelection} className={`block w-full sm:text-sm shadow-inner`} placeholder={`Select gender`} name={`gender`}
       />
</form>

0 likes
13 replies
Sinnbeck's avatar

You are missing a space here

onChange={handleChange}options={genderSelection} 

But check the data with console.log first. What does it show?

Emokores's avatar

@Sinnbeck It's just the formatting as I typed the question but it's well laid out in the code

Emokores's avatar

@Sinnbeck This is what I get: {name: 'Emmanuel Admin', email: '[email protected]', gender: 'M', mobile: '+1 (942) 592-8783', roles: Array(1)}. It seems to be fetching all the necessary data except for roles. I'm having a problem with displaying the checked roles too but we'll get to that in a bit.

Sinnbeck's avatar

@Emokores ok that sounds weird.. You only pass in gender

const {data, setData} = useForm({
       gender: user.gender
})

Or did you remove the others for clarification?

If so, can you show

console.log(gendersSelection) 
Emokores's avatar

@Sinnbeck I removed the others for clarification. And when I console.log(genderSelection) it displays them perfectly well.

Sinnbeck's avatar

@Emokores can you give an example of one item from the array? Or just the whole thing

Emokores's avatar

@Sinnbeck This is what I get: 0: {value: 'm', label: 'Male'} 1: {value: 'f', label: 'Female'}

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Emokores ah casing is wrong. Uppercase M in the data and lowercase m in the array

Sinnbeck's avatar

@Emokores happy to help. Often you just need another set of eyes

Btw. A small tip. You can pass string values like it was html, in react. Example

className="block w-full sm:text-sm shadow-inner" placeholder="Select gender" name="gender" 
1 like
Sinnbeck's avatar

@Emokores if this issue was solved then please mark it as such, and create a new thread. Then I will happily help

If you show what you currently have in react I have something to work with

Please or to participate in this conversation.