javascript - How to set the selected index of a dropdown in reactjs? -


i have 2 dropdowns, second controlled first. when selecting value in first dropdown, sets new list of options second dropdown.

the problem have selected index of second dropdown being remembered, , don't see clear way set selected index. if javascript, i'd set selected index. being react, i'm not sure should do.

render() {         let renderworkitemtypes = (workitemtype: tfs_workitemtracking_contracts.workitemtype) => {             return <option value={workitemtype.name}>{workitemtype.name}</option>;         };          return <select onchange={this.props.workitemtypechanged}>{this.props.workitemtypes.map(renderworkitemtypes) }</select>;     } 

i advice using props value of <select> described react:

<select value="b">  <option value="a">apple</option>  <option value="b">banana</option>  <option value="c">cranberry</option> </select> 

when onchange triggers, edit component state setstate , change <select> value: <select value={this.state.value}>? having select field value depending on component state allows control default value , therefore change when first select field resets second select field.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo