I am trying to render components from a function inside my render statement. I have two map functions and I am trying to return the code. Here is a part of my code:
renderRNAseq() {
const rnaSeq = [];
if (this.state.dataLoaded) {
this.state.resources.map(resource => {
if (resource.category == 'RNA-seq') {
rnaSeq.push(resource);
}
})
return (
rnaSeq.map(res => {
console.log(res);
<Container>
<Row>
<Col sm={4}>
<div className="webApp" key={res.id}>
<Link to={`/apps/${res.parameter}`}><img src={res.logo} /> </Link>
<h4>{res.title}</h4>
</div>
</Col>
</Row>
</Container>
}))
} else {
<p>Loading...</p>
}
}
render() {
return (
<Container className="apps">
{this.renderRNAseq()}
</Container>
)
}
When I did console log, they returned all of the objects in the rnaSeq array, so I know the objects are being pushed into the array, and they should return... but they're not rendering on my site. What's the issue?
Thanks!
renderRNAseq() {
const rnaSeq = [];
if (this.state.dataLoaded) {
this.state.resources.map(resource => {
if (resource.category == 'RNA-seq') {
rnaSeq.push(resource);
}
})
return (
rnaSeq.map(res => {
return <Container>
<Row>
<Col sm={4}>
<div className="webApp" key={res.id}>
<Link to={`/apps/${res.parameter}`}><img src={res.logo} /> </Link>
<h4>{res.title}</h4>
</div>
</Col>
</Row>
</Container>})
)
} else {
return <p>Loading...</p>
}
}
return (
rnaSeq.map(res => {
return (
<Container>
<Row>
<Col sm={4}>
<div className="webApp" key={res.id}>
<Link to={`/apps/${res.parameter}`}><img src={res.logo} /> </Link>
<h4>{res.title}</h4>
</div>
</Col>
</Row>
</Container>
)
}));
}
or
return (
rnaSeq.map(res => (
<Container>
<Row>
<Col sm={4}>
<div className="webApp" key={res.id}>
<Link to={`/apps/${res.parameter}`}><img src={res.logo} /> </Link>
<h4>{res.title}</h4>
</div>
</Col>
</Row>
</Container>
)
));
}
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.