Generate multiple NextJS components
P粉513318114
P粉513318114 2023-07-19 18:17:07
0
1
430

I'm currently learning NextJS and I want to create a website that showcases the multiple projects I've created with it.

I have a component called "Tag" which is a button template with custom text and I want to pass it via props:


export default function Tag({val}) {
    return(
        <>
            <p>{val}</p>
        </>
    )
}

Then, in my Block component, I want to generate a corresponding number of Tag components based on the number of elements in the array passed through props:

import Tag from "./Tag"

export default function Block({tags, name}) {
    return(
        <>
            <section>
                <div></div>
                <h2>{name}</h2>
                <div>
                    {tags.forEach(tag => <Tag val={tag} />)}
                </div>
            </section>
        </>
    )
}

Then, this Block component is called on the home page:

import Block from './components/Block'

export default function Home() {
  return (
    <>
      <Block tags={["Webflow", "UI Design"]} name="Projet 1" />
    </>
  )
}

The problem is: no tags are displayed.

I think the problem is related to the forEach method because when I try to generate a single label without the forEach method it works fine.

What’s the problem?

P粉513318114
P粉513318114

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!