Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. useEffect(() => {
  2. setPage(1);
  3. }, [stateSelected]);
  4.  
  5. useEffect(() => {
  6. const fetchData = async (state, page) => {
  7. setLoading(true);
  8. setApiCalls(c => c + 1);
  9. const from = (page - 1) * CITIES_PER_PAGE;
  10. const to = from + CITIES_PER_PAGE;
  11. const records = await api(state, from, to);
  12. setResults(records);
  13. setLoading(false);
  14. };
  15. if (stateSelected) {
  16. fetchData(stateSelected, page);
  17. }
  18. }, [stateSelected, page]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement