rtk-incubator / rtk-query

Data fetching and caching addon for Redux Toolkit
https://redux-toolkit.js.org/rtk-query/overview
MIT License
626 stars 31 forks source link

Mutation fetch when component mount #236

Closed vaqif14 closed 3 years ago

vaqif14 commented 3 years ago

Is it possible to get data for the first time when the page mount in mutation? (without call with useEffect)

phryneas commented 3 years ago

Mutations are not there for getting data, but for telling the server to change something in the database, like sending a form. It is not really a standard use case to change data on the server every time a site loads, without user interaction, so no, that is not really something we support.

What do you want to do there?

vaqif14 commented 3 years ago

Mutations are not there for getting data, but for telling the server to change something in the database, like sending a form. It is not really a standard use case to change data on the server every time a site loads, without user interaction, so no, that is not really something we support.

What do you want to do there?

Ok, thanks for the reply. I have a table that firstly fetching 1000 data after change page it sends a post request to fetch other new table data. For starting I don't want to use useEffect for clean code 🤪 but no problem

phryneas commented 3 years ago

If this is only fetching data, it should be a query, not a mutation. Doesn't matter if it's a POST or not.

vaqif14 commented 3 years ago

How I can request when the button clicked in a query?

phryneas commented 3 years ago

For pagination purposes, see the pagination example in the docs