Im having trouble setting page = 1
before calling the handleSearchClick
function in resetStates
. Currently when resetStates
is being called (which is after a search button
is clicked) it does not reset page to 1 on the first click but on the second search click it does.
I tried using a async await
but thats not reseting page to 1 before handleSearchClick. How do I reset page to 1 before the function call? Any feedback is appreciated.
This is what Im currently doing:
const resetStates = async () => {
const promise1 = setHasMore(true);
const promise2 = await setPage(1);
Promise.all([promise1, promise2])
.then(() => {
/* At this point I want page to equal 1 */
handleSearchClick();
})
.catch(error => {
throw new Error(error);
});
};
/**
* Handles event on search click
*/
const handleSearchClick = async () => {
setItems([]);
setIsLoading(true);
const base = handleBaseId();
const items = await fetchSearchPayload(page, value, option, base);
setIsLoading(false);
setInitialLoad(true);
setItems(items);
console.log('On Click', { option }, { page });
};
<SearchBar
onClickButton={resetStates}
onValueChange={handleChange}
value={value}
pageNum={page}
onEnter={handleSearchOnEnter}
/>