website/versioned_docs/version-v17.0.0/api-reference/hooks/use-client-query.md
import DocsRating from '@site/src/core/DocsRating';
useClientQuery hook is used to render queries that read only client fields.
The Relay Compiler fully supports client-side extensions of the schema, which allows you to define local fields and types.
# example client extension of the `Query` type
extend type Query {
client_field: String
}
These client-only fields are not sent to the server, and should be updated
using APIs for local updates, for example commitPayload.
const React = require('React');
const {graphql, useClientQuery} = require('react-relay');
function ClientQueryComponent() {
const data = useClientQuery(
graphql`
query ClientQueryComponentQuery {
client_field
}
`,
{}, // variables
);
return (
<div>{data.client_field}</div>
);
}
query: GraphQL query specified using a graphql template literal.variables: Object containing the variable values to fetch the query. These variables need to match GraphQL variables declared inside the query.data: Object that contains data which has been read out from the Relay store; the object matches the shape of specified query.
data above is: {| user: ?{| name: ?string |} |}.useLazyLoadQuery with fetchPolicy: store-only, it does not send the network request.