0

I would like to ask why does my dropdown can't hold the value after selecting.

ClientMaintenancePage.js

/* Dropdown */
const optionsBrstn = [
   'BIC', 'BRSTN', 'Bank Name'
];

const defaultOption = options[0];

<form className="form-horizontal form-group">
      <Dropdown options={optionsBrstn} onSelect={_onSelect} value={defaultOption} placeholder="Select an option" />
      <div className="text-right mt-2">
            <MDBBtn color="indigo" type="button" onClick={() => {}}>Add</MDBBtn>
            <MDBBtn color="indigo" type="button" onClick={() => {}}>Delete</MDBBtn>
            <MDBBtn color="indigo" type="button" onClick={() => {}}>Save</MDBBtn>
      </div>
</form>

It was originally this._onSelect, however I am not using a class component that's why I cannot use the this keyword.

May I know what approach can I use for this using React hooks.

TIA

0

1 Answer 1

1

It should be optionsBrstn. I can not see options variable or state.

const defaultOption = optionsBrstn[0]

One more thing, defaultOption is const so if you change the selected option on change, it will not reflect in your select. It should be kept in a state.

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

2 Comments

I have another question though, what should I put in the onSelect property?
Ofcourse, It depends what you want to do in onSelect.

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.