I'd like to set state of my React component from query values.
componentDidMount() {
const query = queryString.parse(this.props.location.search);
this.setState(query)
}
It works well, but some fileds of state should be integer type. But queryString.parse returns objects which contains only string values. Is there any simple way to convert it? There is Trafaret library in Python, does JS have smth like that?
P.S. I want to use it for paginate, for example. Query params should contains offset, limit, number page etc.
parseInt()is what you are looking for: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…JSON.parse(JSON.stringify(obj))this.props.location.searchlook like?