我的应用程序看起来类似于下面的片段中包含的内容。
(我遗漏了很多实现细节,希望下面的代码足以解决我的问题)。
SampleApp.js
const SampleAppQuery = graphql`
list SampleAppQuery {
...ItemComponent_item
}
`
function SampleApp() {
return (
<QueryRenderer
environment={environment}
query={SampleAppQuery}
render={(error, props) => {
if (props) {
return <AppRefetchContainer list={props} />
}
}}
/>
)
}
AppRefetchContainer.js
class AppRefetchContainer extends Component {
render() {
<div>
<HeaderComponent refetchList={this._refetchList} />
{list.map(item => <ItemComponent item={item} />)}
</div>
}
_refetchList(params) {
this.props.relay.refetch(params)
}
}
export default createRefetchContainer(
AppRefetchContainer,
graphql`
fragment AppRefetchContainer_list on Item {
...ItemComponent_item
}
`,
graphql`
query AppRefetchContainerQuery($sortBy: String!)
list SampleAppQuery(sortBy: $sortBy) {
...ItemComponent_item
}
`
)
初始应用程序负载很好。单击其中一个标题应触发重新获取,以便可以根据传递的 inparams 对列表数据进行排序。当我触发重新获取时,服务器会以正确的数据进行响应,但是,组件不会重新呈现。
我怀疑我的问题在于我在这里定义片段的方式。我在初始页面加载时遇到的控制台错误是:
RelayModernSelector: Expected object to contain data for fragment
`AppRefetchContainer_list`, got `{"list":[{"__fragments":
{"ItemComponent_item":{}},"__id":"[some_valid_id]","__fragmentOwner":null},{...
问题):
我不完全确定如何解释该错误。这是我无法重新渲染 UI 的原因吗?
我知道这种方法可能并不理想,但我如何
refetch
从不一定是查询片段的组件中获取?
很高兴提供任何澄清或缺失的上下文:)