[英]relay-modern FragmentContainer outside QueryRenderer
Is it possible? 可能吗? Can we use
FragmentContainer
outside a QueryRenderer? 我们可以在QueryRenderer之外使用
FragmentContainer
吗? What I want to achieve: I have a RefetchContainer
with a SectionList
. 我想什么来实现的:我有一个
RefetchContainer
与SectionList
。 Every item inside each section is a FragmentContainer
. 每个部分中的每个项目都是一个
FragmentContainer
。 When I select an item from a section, I want to open a new screen where I display a FlatList
of these items. 当我从一个部分中选择一个项目时,我想打开一个新屏幕,在其中显示这些项目的
FlatList
。 The data I pass from the SectionList
on item select is a list of FragmentContainer
. 我从
SectionList
项的SectionList
传递的数据是FragmentContainer
的列表。 Thus I can't see the data so I need to use fragments for it. 因此,我看不到数据,因此需要使用片段。 If I use just fragments inside the
FlatList
I get a missing environment from the RelayFragmentContainer
. 如果仅在
FlatList
使用片段, FlatList
从RelayFragmentContainer
获取缺少的环境。 So I added a QueryRenderer as parent for the FlatList
where I request the same single section once again. 所以我增加了一个QueryRenderer作为父母的
FlatList
,我再次请求相同的单节。 But this makes an extra QueryRenderer
request. 但这会产生一个额外的
QueryRenderer
请求。 I want to display the data from the previous screen. 我想显示上一个屏幕中的数据。 At least I pass this list of
FragmentContainer
as cacheConfig and return it from the fetchQuery
method but, the json differs from the response json hence it is not raw data but already __fragments
, thus the Relay
cannot parse it. 至少我将此
FragmentContainer
列表作为fetchQuery
传递,并从fetchQuery
方法返回它,但是json与响应json不同,因此它不是原始数据,但已经是__fragments
,因此Relay
无法对其进行解析。
It would be good to get some code examples in this question of what your components and fragments look like. 在这个问题中获得一些代码示例,以了解您的组件和片段是什么样子是很好的。 That said, you might want to investigate using the
@mask
directive. 也就是说,您可能想使用
@mask
指令进行调查。
I've taken an example from the Relay documentation and included it here: 我从中继文档中获取了一个示例,并将其包含在此处:
module.exports = createFragmentContainer(
({ user }) => ...,
graphql`
fragment Component_user on User {
internUser {
manager {
...Component_internUser @relay(mask: false)
}
.... on Employee {
admins {
...Component_internUser @relay(mask: false)
}
reports {
...Component_internUser @relay(mask: false)
}
}
}
}
fragment Component_internUser on InternUser {
id
name
}
`,
);
By using the @mask
data included from a fragment will be available in the component that is hosting the fragment. 通过使用
@mask
,片段中包含的数据将在承载该片段的组件中可用。 Relay documentation about this is available here: https://facebook.github.io/relay/docs/relay-directives.html#relay-mask-boolean 关于此的中继文档可在以下位置找到: https : //facebook.github.io/relay/docs/relay-directives.html#relay-mask-boolean
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.