I am facing this error while using URLSearchParams
TypeError: url__WEBPACK_IMPORTED_MODULE_2__.URLSearchParams is not a constructor
This is how I am calling:
componentDidMount() {
const query = new URLSearchParams(this.props.location.search); // <- ERORR
const ingredients = {};
for (let param in query.entries()) {
// ['salad', '1']
ingredients[param[0]] = +param[1];
}
this.setState({ingredients : ingredients});
}
My ReactJS Project details:
"dependencies": {
"axios": "^0.19.0",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1"
},
This happens when react import UrlSearchParams from 'url' So you have to remove this and try it. It will definitely work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With