I was trying to change query so what i am fetching would update, but it only updates i put there for testing. I would really appreciate help. And is it better to use this class method or learn using hooks? Since when i was googling i found something of a solution, but it was using hooks.
class App extends Component {
constructor() {
super();
this.state = {
search: '',
photos: [],
query: 'space'
}
this.handleClick = this.handleClick.bind(this)
}
async componentDidMount() {
const {query} = this.state
try{
const responseSearch = await client.photos.search({query, per_page: 20 });
const dataSearch = await responseSearch.photos;
console.log(responseSearch)
this.setState({photos: dataSearch})
if (responseSearch.ok) {
throw Error(responseSearch.statusText);
}
}catch (error) {
console.log(error);
}
}
handleClick(){
this.setState({query: 'nature'})
}
render() {
const {photos, search, query} = this.state;
const filteredImages = photos.filter( card =>
card.photographer.toLowerCase().includes(search.toLowerCase() )
)
return (
<div className="App">
<Particles className ='particles'
params={particlesOptions}
/>
<h2>{query}</h2>
<button onClick={this.handleClick}>change</button>
<Nav
categories={categories}
/>
<SearchBox
placeholder='search cards'
handleChange={e => this.setState({query: e.target.value})}
/>
<CardGroup cards={filteredImages} />
</div>
);
}
}