1

I am working on a dropdown select filter and there is a reset button, so I want to reset data whenever I click on it. this is my select dropdown where I am filtering data

<select
    className={style.input}
    name="categoryId"
    onChange={e => handleCategory(e.target.value)}
>
    <option value="" disabled selected>
        Select A Categtory
    </option>
    {props.category_list && props.category_list.length > 0
        ? props.category_list.map((item, index) => (
              <option value={item.categoryId}>{item.categoryName}</option>
          ))
        : null}
</select>

this is onChange method of select

 const handleCategory = (value) => {
    setErrorMsg(null);
    setCategoryID(value);
    props.getSubCategoryList(value);
  };

and this is a reset button, I tried to make

  const handleReset = (value) => {
    setReset(true);
    setCategoryID('');
    setSkillID('');
    setLocationId('');
    props.getSubCategoryList(1);
  };

but the problem is when I click on reset it resets, but the value doesn't change to default one in options also if I change it in {item.categoryName} then three same values appear under options. hope this information is enough.

1 Answer 1

1

You need to bind the selected value to select element.

  1. Provide categoryID as a prop to your component.
  2. Set it as the value property of select.
<select
    ...
    ...
    value={props.categoryID}
    onChange={e => handleCategory(e.target.value)}
></select>
Sign up to request clarification or add additional context in comments.

1 Comment

@How to Program, check this out !!

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.