Joe*_*ona 13
如果我理解正确,那么在用户输入一些搜索文本之前,您根本不想为该组件发送任何查询,此时应该发送查询.这可以通过@Xuorig发布的示例完成,还有一个补充:使用GraphQL的@include指令跳过片段,直到设置变量.这是扩展示例:
export default Relay.createContainer(Search, {
initialVariables: {
count: 3,
query: null,
hasQuery: false, // `@include(if: ...)` takes a boolean
},
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
# add `@include` to skip the fragment unless $query/$hasQuery are set
items(first: $count, query: $query) @include(if: $hasQuery) {
edges {
node {
...
}
}
}
}
`,
},
});
Run Code Online (Sandbox Code Playgroud)
由于包含条件是假的,因此最初将跳过此查询.然后,组件可以setVariables({query: someQueryText, hasQuery: true})在文本输入更改时调用,此时@include条件将变为true并且查询将被发送到服务器.
| 归档时间: |
|
| 查看次数: |
986 次 |
| 最近记录: |