0

Button working only on double click.

Hello guys, I am working on an unsplash application. I fetched the data using unsplash api. I added a total of 3 buttons. One button named 'GO' is working fine but the other 2 buttons named 'HILLS' 'BEACH' are working on double click which I want to work in one click. These two buttons fetch data of hills and beach while the GO button is like a submit button for the search bar. Sorry for the code I don't know how to run a component in solo learn. Please help me. Thanks in advance. https://code.sololearn.com/Wbg6Vs0eT3cm/?ref=app

3rd Jan 2021, 7:32 AM
Venkat Ram
Venkat Ram - avatar
6 Respuestas
+ 1
In your code you are setting the state and using it in the fetchImages() function, as soon as the setSearch is set the component re renders and the fetchImages() has the previous value of search as undefined Although, There's still some issue, You can get rid of the go button now
4th Jan 2021, 3:08 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
3rd Jan 2021, 11:17 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
Ya the buttons are working on double click but I want those to work on single click.
4th Jan 2021, 2:08 PM
Venkat Ram
Venkat Ram - avatar
0
Venkat Ram ok, check now it's working
4th Jan 2021, 2:17 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
Thanks a lot it's working 🙂 Can you please point my mistake? Thanks in advance. Мг. Кнап🌠
4th Jan 2021, 2:54 PM
Venkat Ram
Venkat Ram - avatar
0
Thanks a lot!!
6th Jan 2021, 10:48 AM
Venkat Ram
Venkat Ram - avatar