john-smilga / react-projects

4.78k stars 3.86k forks source link

Need clarification - 02: Tours #30

Closed Lbhagi closed 2 years ago

Lbhagi commented 3 years ago

While removing tours, I called {fetchTours()} on refresh button instead of {fetchTours}

Then I see Loading.. and the list of tours displayed. It supposed to be Refresh button and text as "No Tours Left". If I click refresh then all tours has to be displayed.

Can you explain difference between calling fetchTours vs fetchTours() onclick event of Refresh button?

Chronoviser commented 2 years ago

{fetchTours} waits for you to click the button, then it calls fetchTours() But {fetchTours()} calls fetchTours() as soon as this statement is compiled, and doesn't depend on the user to click the button.