Reactjs 函数作为子函数无效。如果返回的是组件而不是<;组件/>;从渲染
我想在我的页面上显示发送帖子,但有一个错误: 函数作为子函数无效。这可能会发生,如果你 返回组件,而不是从渲染返回。或者你 用于调用此函数而不是返回它 代码如下:Reactjs 函数作为子函数无效。如果返回的是组件而不是<;组件/>;从渲染,reactjs,Reactjs,我想在我的页面上显示发送帖子,但有一个错误: 函数作为子函数无效。这可能会发生,如果你 返回组件,而不是从渲染返回。或者你 用于调用此函数而不是返回它 代码如下: import React,{Component}来自'React'; 从'react dom'导入{render}; const rootNode=document.getElementById('root'); 类Blog扩展组件{ 建造师(道具){ 超级(道具); this.Header=this.Header.bind(this
import React,{Component}来自'React';
从'react dom'导入{render};
const rootNode=document.getElementById('root');
类Blog扩展组件{
建造师(道具){
超级(道具);
this.Header=this.Header.bind(this);
this.UnderHeader=this.UnderHeader.bind(this);
}
标题(){
this.props.posts.map(post=>{post.title} );
}
标题下(){
this.props.posts.map(post=>{
返回(
{post.title}
{post.content}
);
});
}
render(){
返回(
{this.Header}
{this.UnderHeader}
);
}
}
常数员额=[
{id:1,标题:'title1',内容:'content1'},
{id:2,标题:'title2',内容:'content2'},
{id:3,标题:'title3',内容:'content3'},
{id:4,标题:'title4',内容:'content4'}
];
render(,rootNode);
如果要呈现JSX
this.Header()
,this.Header
是一个函数引用,但不调用它map
的结果,`map返回需要从函数返回的JSX组件数组const{Component}=React;
const{render}=ReactDOM;
const rootNode=document.getElementById('root');
类Blog扩展组件{
建造师(道具){
超级(道具)
this.Header=this.Header.bind(this)
this.UnderHeader=this.UnderHeader.bind(this)
}
标题(){
返回这个.props.posts.map((post)=>{post.title} )
}
标题下(){
返回此.props.posts.map((post)=>{
返回(
{post.title}
{post.content}
)
})
}
render(){
返回(
{this.Header()}
{this.UnderHeader()}
)
}
}
警察哨所=[
{id:1,标题:'title1',内容:'content1'},
{id:2,标题:'title2',内容:'content2'},
{id:3,标题:'title3',内容:'content3'},
{id:4,标题:'title4',内容:'content4'},
]
渲染(
,
根节点
)
我知道这方面的错误!render(){return(
- {this.Header}
{this.UnderHeader})}