My react page consist of three dropdown list, each dropdown has it own respective set of data, which is being pulled from a json file. My issue is, one of the dropdown list repeats the client's name several times (the clients name comes up more then once in the dropdown). Is there a way to prevent the client's name from duplicating?
this is my code:
import React, { Component } from 'react';
class Ast extends Component {
constructor(){
super();
this.state = {
data: [],
cfmRateFactor: "10",
};
} //end constructor
change = (e) => {
this.setState({
[e.target.name]: e.target.value
});
}; //end change
removeDuplicates(arr) {
let data = arr.filter(function(elem, index, self) {
return index == self.indexOf(elem);
});
return unique_array
}
componentWillMount() {
fetch('https://api.myjson.com/bins/b1i6q', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
},
/*body: JSON.stringify({
username: '{userName}',
password: '{password}'
})*/
}) /*end fetch */
.then(results => results.json())
.then(data => this.setState({ data: data })
)
} //end life cycle
render() {
console.log(this.state.data);
return (
<div>
<div className="container">
<div>
<form>
<div>
<h2>Memeber Selection:</h2>
{['clientName', 'siteName', 'segmentName'].map(key => (
<div className="dropdown-padding">
<select key={key} className="custom-select">
{this.state.data.map(({ [key]: value }) => <option key={value}>{value}</option>)}
</select>
</div>
))}
</div>
<div className="txt_cfm">
<label for="example-text-input">Modify CFM Rate Factor:</label>
<input class="form-control" type="textbox" id="cfmRateFactor" name="cfmRateFactor" value={this.state.cfmRateFactor} onChange={e => this.change(e) } />
</div>
<div>
<div>
<button type="submit" className="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
);
}
}
export default Ast