Whenever Relay is fulfilling data requirements, it can be useful to know when certain events occur. For example, we might want to record how long it takes for data to be available, or we might want to log errors to the server. These events are available on most Relay APIs via the onReadyStateChange callback.
onReadyStateChange When Relay fulfills data, the onReadyStateChange callback is called one or more times with an object that describes the current "ready state". This object has the following properties:
ready: boolean
This is true when the subset of data required for rendering is ready.
done: boolean
This is true when all data requirements are ready for rendering.
error: ?Error
This is an instance of Error if there is a failure. Otherwise, this is null.
events: Array<ReadyStateEvent>
This is an array of events received so far (see ReadyStateEvent below).
stale: boolean
When "force fetching", this is true if ready is true as a result of data being available on the client before the server request has completed.
aborted: boolean
Whether the request was aborted.
ReadyStateEvent ABORTCACHE_RESTORED_REQUIREDCACHE_RESTORE_FAILEDCACHE_RESTORE_STARTNETWORK_QUERY_ERRORNETWORK_QUERY_RECEIVED_ALLNETWORK_QUERY_RECEIVED_REQUIREDNETWORK_QUERY_STARTSTORE_FOUND_ALLSTORE_FOUND_REQUIREDIf insufficient data on the client leads Relay to send a server request for more data, we can expect the following behavior:
ready set to false.ready and done set to true.If sufficient data is available on the client such that Relay does not need to send a server request, we can expect the following behavior:
ready and done set to true.If a server request results in a failure to load data, we can expect the following behavior:
ready set to false.error set to an Error object.Note that ready and done will continue to be false.
If a "force fetch" occurs and there is insufficient data on the client, the same behavior as Fetching Data from the Server can be expected. However, if a "force fetch" occurs and there is sufficient data on the client to render, we can expect the following behavior:
ready, done, and stale set to true.ready and done set to true, but stale set to false.
© 2013–present Facebook Inc.
Licensed under the BSD License.
https://facebook.github.io/relay/docs/guides-ready-state.html