Should I store search result in redux store?

2019-06-19 03:08发布

问题:

Search result in general is temporary in nature.

I don't see much point storing the search result in the store.

Should I use react's setState to render the search results in this case?

回答1:

Depends, one use case for storing the search results in the store is:

  1. Users goes to /search and searches for "awesome cheap cars"
  2. User clicks on the third car that appears in the results list
  3. User does not like the car, and presses the back button in the browser

Now, if you stored the search query and the search result in the store, you can rerender the search page with the same results without another rountrip to the server and it will look like instant loading to the user.

I would personally store the results in store.search



标签: reactjs redux