React Apollo - Auto Refetch

Apollo made react fectching and updating data much more easy and simple.

To enable auto-refetch data we just need to define a pollInterval option :

options: { pollInterval: 20000 }

If you use a function to compute options from props, all of these options will be automatically recalculated whenever the props change.

 

Example :

export default graphql(UserListQueries, {

name: 'userListQueries',

options: { pollInterval: process.env.REACT_APP_REFETCH_USERS_INTERVAL },

})(UserListPage)

 

https://github.com/helabenkhalfallah/react-apollo-redux-graphql


Read More :

https://www.apollographql.com/docs/react/basics/queries.html#graphql-query-options

 

 

best practices reactjs

×