我刚开始使用 react-apollo,想知道跨组件共享数据的最佳方式是什么。
例如,我componentA使用grapqlfromreact-apollo来获取一些数据 ( WrappedA)。我还有一些其他组件,componentB在我的 UI 中的其他地方,并且想要使用已经由componentA. 下面附上一个非常简单的例子。
const ComponentA = ({ ...props }) => (
<div>
ComponentA...
id: {props.organisationsData.organisations.id}
</div>
)
const ComponentB = ({ ...props }) => (
<div>
****** Want to access props.organisationsData *****
ComponentB...
</div>
)
const organisationsQuery = gql`
query organisations {
organisations {
id
name
}
}
`
const WrappedA = graphql(organisationsQuery, { name: 'organisationsData' })(WrappedA)
const Container = ({ ...props }) => …Run Code Online (Sandbox Code Playgroud)