1 | ## React APIs for Relay
|
2 |
|
3 | This package contains a collection of React APIs: Hooks and Components that are
|
4 | integrated with Relay runtime.
|
5 |
|
6 | Example:
|
7 |
|
8 | ```js
|
9 | // @flow
|
10 |
|
11 | import type {UserComponent_user$key} from 'UserComponent_user.graphql';
|
12 |
|
13 | const React = require('react');
|
14 |
|
15 | const {graphql, useFragment} = require('react-relay');
|
16 |
|
17 | type Props = {
|
18 | user: UserComponent_user$key,
|
19 | };
|
20 |
|
21 | function 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 |
|
45 | For complete API reference, visit https://relay.dev/.
|