now we've got to provide that autorization thing and that's really long url.
all that stuff that propably should not belong directly inside of our app class.
to fix this stuff up i'm going to flip back over to the unsplash file.
the nice thing about axios is that you can kind of set up a preconfigured instance of the axios client that has default properties set for where it's going to make a request to or headers and even params if you wanted to as well.
<unsplash.js>
import axios from 'axios';
export default axios.create({
// going to get route & url or just domain from App.js and paste as below
baseURL: 'https://api.unsplash.com',
headers: {
Authorization: 'Client-ID Rw6et1-um043INr5rEgB3uiIeQHs_6LlF5UMrDcEUws',
},
});
<App.js>
import React from 'react';
import unsplash from '../api/unsplash';
import SearchBar from './SearchBar';
class App extends React.Component {
state = {
images: [],
};
onSearchSubmit = async anything => {
const response = await unsplash.get('/search/photos', {
params: { query: anything },
});
this.setState({ images: response.data.results });
};
render() {
return (
<div className="ui container" style={{ marginTop: '10px' }}>
<SearchBar onSubmit={this.onSearchSubmit} />
Found :{this.state.images.length} images
</div>
);
}
}
export default App;