1

I have the following code but when i change the value from drop-down the drop-down sticks to Select the status Rather changing it to the selected value i.e

const [formData, setFormData] = useState({
    title: "",
    status: "",
    priority: "",
    start_date: new Date(),
    due_date: new Date(),
    progress: 0,
    user_id: null,
  });

const task_statuses = ["active", "pending", "inactive", "completed"];

  const setData = (e) => {
    setFormData({ ...formData, [e.target.name]: e.target.value });
  };
    <select onChange={setData} name="status">
      <option value=""> Select Task Status </option>
        {task_statuses.map((status) => {
          return (
            <option key={shortid.generate()} value={status}>
              {capitalizeFirstLetter(status)}
            </option>
          );
        })}
      </select>

I would like it to change it to selected option, can't do it please help

Please Help

1

1 Answer 1

1

Because you are not setting value prop of select tag

Add value prop to value={formData.priority}

<select onChange={setData} value={formData.priority} name="status">

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.