Reactjs 反应&;阿波罗:元素没有返回
出于某种原因,在使用时:Reactjs 反应&;阿波罗:元素没有返回,reactjs,react-router,graphql,apollo,Reactjs,React Router,Graphql,Apollo,出于某种原因,在使用时: export const allBilderLinkses = gql` query bild($name: String!){ allBilderLinkses(filter: {collectionName: {collectionName: $name}}) { bildLink } } ` const Images = ({ data: { loading, error, allBilderLinkses } }) => { if (
export const allBilderLinkses = gql`
query bild($name: String!){
allBilderLinkses(filter: {collectionName: {collectionName: $name}}) {
bildLink
}
}
`
const Images = ({ data: { loading, error, allBilderLinkses } }) => {
if (error) return <h1>Error fetching the post!</h1>;
if (!loading) {
return (
<div>
{allBilderLinkses.map(bild => (
<ImageContainer bg={bild.bildLink}/>
))}
</div>
);
}
return <h2>Loading post...</h2>;
};
class ExpandedCard extends Component {
render() {
return (<div>
<Container>
<h1>test</h1>
</Container>
<Images />
</div>
);
}
}
export default graphql(allBilderLinkses, {
options:({match}) => ({ variables: {
name: match.params.id
},
notifyOnNetworkStatusChange: true,
}),
}) (Images, ExpandedCard);
export const allBilderLinkses=gql`
查询图片($name:String!){
allBilderLinkses(筛选器:{collectionName:{collectionName:$name}){
bildLink
}
}
`
常量图像=({data:{loading,error,allBilderLinkses}})=>{
if(error)返回获取帖子时出错!;
如果(!加载){
返回(
{allBilderLinkses.map(bild=>(
))}
);
}
返回装载站。。。;
};
类ExpandedCard扩展组件{
render(){
返回(
测试
);
}
}
导出默认图形QL(allBilderLinkses{
选项:({match})=>({变量:{
名称:match.params.id
},
notifyOnNetworkStatusChange:true,
}),
})(图像、扩展卡);
仅呈现
<代码>测试不会被渲染,事实上,通过chrome开发工具,h1标签甚至不是一个元素。
通常在我的构建中,gql查询不会干扰组件的其余部分。我在这段代码中看到的唯一区别是gql查询中添加的变量和graphql的export语句中的变量选项。
似乎没有理由不加载h1标记,为什么要这样做?我怎样才能修好它 您需要删除graphql HoC调用中的第二个参数 它应该是
graphql(…)(扩展卡)
graphql是一个HoC(高阶组件)。它可以被认为是一个组件,它接受一个组件作为输入,并返回一个增强的组件。HoC用于跨组件共享横切关注点
所以graphql如下所示
const graphql = (wrappedComponent, someData) => () => <WrappedComponent {...graphql props based on someData} />
constgraphql=(wrappedComponent,someData)=>()=>
包装组件是您希望使用graphql功能增强的组件。容器标记的渲染功能是什么?看起来它的呈现中可能没有this.props.children?容器标记只是一个styled.div,没有呈现函数…啊,我发现了您的错误。