React-apollo: onComplete being called on every render

Created on 21 Oct 2018  路  8Comments  路  Source: apollographql/react-apollo

The changes made related to issue #2177 causes onCompleted to be called on every render. Before it was called once.

That might break the app causing a Maximum update depth exceeded error if trying to setSate with the data provided.

Most helpful comment

same problem.

All 8 comments

same problem.

Does anyone know the propper way to only setState after server call? Thanks.

This is happening to me as well.

This seems to be functioning differently from what I understand the intended behavior of onCompleted to be.

Any hints as to why this is happening?

you can add an if else condition in completed function in order to prevent what will change state again and again.

       <Query
            query={XXXXX}
            onCompleted={(data) => {
              if (!initValue) {
                   ...do something
              }
            }}
          >

This has been fixed in current day versions of react-apollo. Thanks!

That's great! @hwillson Thank you for updating this ticket!

still happening actually...

@kcvin94 Should be fixed in the newly released v3.1.0. See #3353 for more details.

Was this page helpful?
0 / 5 - 0 ratings