中继createFragmentContainer是有用的功能,易于使用:
const MyComponent = createFragmentContainer(
MyFragmentComponent,
{
job: graphql`
fragment MyComponent_job on Job {
id
}
`
}
);
问题是,当查询位于文件末尾时,确实很难读取代码。我更喜欢在导入后将其放在右上角。像这样:
const QUERY_FRAGMENT = graphql`
fragment MyComponent_job on Job {
id
}
`
// Main code here
const MyComponent = createFragmentContainer(
MyFragmentComponent,
{
job: QUERY_FRAGMENT
}
);
但是在这种情况下,中继编译器会引发错误: FindGraphQLTags: 'createFragmentContainer' expects fragment definitions to be 'key: graphql'.
createFragmentContainer
和graphql
?这似乎是的已知问题babel-plugin-relay
。如本期所述,解决方法是更改导入:
import Relay, { graphql } from 'react-relay'
const fragment = graphql`...`
...
Relay.createFragmentContainer(Component, fragment)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句