search functionality using relay

前端 未结 2 1181
闹比i
闹比i 2020-12-16 02:47

How to implement a search functionality with relay?

So, the workflow is

  • user navigate to search form.

there should not be

2条回答
  •  难免孤独
    2020-12-16 03:23

    This is the way I've implemented simple search in my project:

    export default Relay.createContainer(Search, {
      initialVariables: {
        count: 3,
        title: null,
        category: null,
      },
      fragments: {
        viewer: () => Relay.QL`
          fragment on Viewer {
            items(first: $count, title: $title, category: $category) {
              edges {
                node {
                  ...
                }
              }
            }
          }
        `,
      },
    });
    

    Your search form simply has to update the initialVariables using this.props.relay.setVariables and relay will query the new data.

提交回复
热议问题