I Would like to change the Axios base URL according to the userInput. I'm using the google books API and want to alter the search query (q=) based on whatever is entered in the inputbox.
I think this could be done by placing the baseURL inside a function and calling it onClick of the submit button.
const baseURL = `https://www.googleapis.com/books/v1/volumes?q={input}`;
export default function App() {
const [post, setPost] = React.useState(null);
React.useEffect(() => {
axios.get(baseURL).then((response) => {
setPost(response.data);
});
}, []);
if (!post) return null;
return (
<>
<input placeholder="bookname"></input>
<button>Submit</button>
<h1>{post.items[0].volumeInfo.title}</h1>
<h2>{post.items[0].volumeInfo.publisher}</h2>
<img src={post.items[0].volumeInfo.imageLinks.thumbnail} />
</>
);
}
Thanks!