I have dependent fields like this
If you are just using jquery and select2 in a react application, you can simply link the cdn for Jquery and select2 in public/index.html inside "head" tag. Then in your src/components/component.js. You can use jquery select2 like this:
constructor(props) {
super(props);
this.state = {
Provinces: [],
};
this.select2PX = this.select2PX.bind(this);
// this.ApiTest = this.ApiTest.bind(this);
}
select2PX(){
window.$(document).ready(function() {
window.$('#phuong-xa').select2();
});
}
componentDidMount(){
this.select2PX();
}
render(){
return (.... html);
}
Because you use the cdns in the public/.html file, you need to use window.$ to use jquery. It achieves the same thing as using select2 in a html file.