For some reason the graphql higher order function is not behaving as expected, specifically the query is not even being called. This is what I have right now:
function viewReducer({ dispatch, value }) {
let temp = () => (<MyPage
onReconnect = {() => {dispatch(restartSetup());}}
/>);
let View = graphql(myQuery)(temp);
return <View />
}
export { viewReducer };
What exactly I'm missing here?
graphql react-apollo documentation.
Edit : After some debugging it looks like props are not being passed to the actual component. Updated code for debugging:
function viewReducer({ dispatch, value }) {
let temp = () => (<MyPage
onReconnect = {() => {dispatch(restartSetup());}}
/>);
let View = graphql(myQuery,
options: {
fetchPolicy: 'cache-and-network'
},
props: (props) => {
console.log("[INFO] " + JSON.stringify(props))
return props;
}
)(temp);
return <View />
}
I can see the data fetched but the props are not being passed, it's still undefined.
Fixed.
The problem was here:
let temp = () => (<MyPage
onReconnect = {() => {dispatch(restartSetup());}}
/>);
As this closure is not accepting the props as arguments, it is executed and rendered as it is. To fix this I just added the props as argument:
let temp = ({data}) => (<MyPage
onReconnect = {() => {dispatch(restartSetup());}}
data = {data}
/>);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.