import React, { Component } from 'react';
import Axios from 'axios';
class App extends Component {
state = {
posts: []
}
componentDidMount() {
Axios.get('https://jsonplaceholder.typicode.com/posts?id=2&id=3')
.then(response => {
this.setState({ posts: response.data })
})
}
render() {
return(
<div>
{
this.state.posts.map ( (el,k) => <li> {el.title} </li> )
}
</div>
)}
}
export default App;
I am learning how to pass query params while calling APIs. The above code is working fine for me. Here i have passed id=2&id=3 as query params. I am using the following URL
Now, I am failing to pass title in the URL as params also. For e.g. the key-value pair of id=5 is "title": "nesciunt quas odio". So what is the proper way to pass it? Since the title has string value with the spaces in between.
My code should print the titles of id=2, id=3 and id=4; but for id=4 i shall pass the title itself in the params instead of id.
So, following command is rendering nothing on DOM
Axios.get('https://jsonplaceholder.typicode.com/posts?id=2&id=3&title=eum et est occaecati')