sibelius
8/20/2017 - 7:28 PM

Relay properly used

Relay properly used


const UserRow = ({ user }) => (
  <View>
     <Text>{user.name}</Text>
     <Text>{user.email</Text>
  </View>
);

const UserRowFragmentContainer = createFragmentContainer(UserRow, {
   user: graphql`
      fragment UserRow_user on User {
         name
         email
      }
   `
});
            
const UserList = ({ viewer }) => (
  <View>
     {viewer.users.edges.map(({node}) => <UserRowFragmentContainer key={node.id} user={node} />))}
  </View>
);

const UserListFragmentContainer = createFragmentContainer(UserList, {
  viewer: graphql`
    fragment UserList_viewer on Viewer {
       users(first: 10) { 
          edges {
            node {
               id
               ...UserRow_user
            }
          }
       }
    }
  `
})