UNPKG

802 BMarkdownView Raw
1## React APIs for Relay
2
3This package contains a collection of React APIs: Hooks and Components that are
4integrated with Relay runtime.
5
6Example:
7
8```js
9// @flow
10
11import type {UserComponent_user$key} from 'UserComponent_user.graphql';
12
13const React = require('react');
14
15const {graphql, useFragment} = require('react-relay');
16
17type Props = {
18 user: UserComponent_user$key,
19};
20
21function UserComponent(props: Props) {
22 const data = useFragment(
23 graphql`
24 fragment UserComponent_user on User {
25 name
26 profile_picture(scale: 2) {
27 uri
28 }
29 }
30 `,
31 props.user,
32 );
33
34 return (
35 <>
36 <h1>{data.name}</h1>
37 <div>
38 <img src={data.profile_picture?.uri} />
39 </div>
40 </>
41 );
42}
43```
44
45For complete API reference, visit https://relay.dev/.