I am making a select element in Reactjs/HTML and I want to set a default value based on a component variable.(the default value of the select is the id of a component)
this is how I am doing this:
<select
className="p-select-input"
id="Substatus"
defaultValue={task.SubStatus.Id}
>
{projectStatuses.map((status) => {
return (
<option key={status.Id} value={status.Id}>
{status.StatusName}
</option>
);
})}
</select>
This seems to work sometimes and other times it just selects the first option. I cannot figure out why it is doing this. Especially since I have another select component where I do the same thing:
<select
className="p-select-input"
id="Asignee"
defaultValue={task.AsigneeId}
>
{employees.map((Employee) => {
return (
<option key={Employee.EmployeeID} value={Employee.EmployeeID}>
{Employee.Name}
</option>
);
})}
</select>
and again this one works everytime.
just for good messure this is what the 'task' object looks like
AsigneeId: 2403
Deadline: "2023-03-31T00:00:00"
ID: 53
ProjectId: 16677
SubStatus: Object { Id: 4, ProjectId: 0, StatusName: "Wachten op" }
Id: 4
ProjectId: 0
StatusName: "Wachten op"
<prototype>: Object { … }
SubStatusIndex: 2
Summary: "Testing"
Can anyone help me?