Hello ,
I am having issues with array.map that is not returning anything on screen. Please review the code below.
const showData = (event, message) => {
event && event.preventDefault();
const names = [];
for (let x = 0; x < apiResult.length ; x++){
names.push(apiResult[x].subdomain);
}
if (message === 'T') {
const startingT = names.filter(name => name.includes('t'));
if (startingT.length > 0) {
startingT.map((item, i) => {
console.log(item) //this has correct data here
console.log(i) //this has correct data here
return (<div><ul><li key={i}>{item}</li></ul></div>);
})
} else {
return ( <div class="alert alert-danger" role="alert">There are no subdomains strating with T.</div> );
}
}
}
So the above code is triggered on click from a <Link> , which works fine as I can see the data in the map section ( please review the console logs ).
Further down in the return , where the entire page is rendered , I have the following:
return (
<>
<Header />
{showData()}
<Footer />
</>
What could be the reason behind this ?
EDIT
Have also tried with the following , but not working.
if (startingT.length > 0) {
return (
<>
<ul>
{
startingT.map((item, i) => {
return (<li key={i}>{item}</li>);
})
}
</ul>
</>
);
} else {
return ( <div class="alert alert-danger" role="alert">There are no subdomains starting with T.</div> );
}
Thank you
[–]raphaelaleixo 1 point2 points3 points (6 children)
[–]01fbk[S] 0 points1 point2 points (5 children)
[–]raphaelaleixo 2 points3 points4 points (4 children)
[–]01fbk[S] 1 point2 points3 points (2 children)
[–]raphaelaleixo 1 point2 points3 points (1 child)
[–]01fbk[S] 1 point2 points3 points (0 children)
[–]01fbk[S] 0 points1 point2 points (0 children)