Skip to main content
Version: v21.0.1

loadQuery

loadQuery

This function is designed to be used with the usePreloadedQuery() hook to implement the "render-as-you-fetch".

Query references returned from loadQuery will leak data into the Relay store if .dispose() is not called on them once they are no longer referenced. As such, prefer calling useQueryLoader when possible, which ensures that query references are disposed for you.

See the usePreloadedQuery docs for a more complete example.

const MyEnvironment = require('MyEnvironment');
const {loadQuery} = require('react-relay');

const query = graphql`
query AppQuery($id: ID!) {
user(id: $id) {
name
}
}
`;