-1

Each sibling has an id, but still doesn't work. Passed the id inside the first div and still asking for different id. I don't understand ths issue here. Is my id recognized and with the good type ? Or do I need to put another div with only the id before this one ?

import React from 'react';
import listProjects from "./JSONdata/projects.json"

export default function Project(){
    return(
        <div className="projectList">
        {listProjects.projects.map(project => (
            displayProject(project)
        ))}
        </div>
    )
}

function displayProject(project){
    return(
        <>
            <div className="projectContainer">
                <div className="imgContainer">
                </div>
                <div className="nameProject">
                    <a href={project.gitlabLink}><p>{project.name}</p></a>
                </div>
                <div className="technologiesProject">
                    {
                        project.technologies.map(({techno, id}) =>(
                            <div className={`${techno}Container`} key={id}>
                                <p>{techno}</p>
                            </div>

                        ))
                    }
                </div>
            </div>
        </>
    )
}

And the data from JSON looks like this

{
    "projects": [
        {
            "name": "PoE AiO",
            "gitlabLink": "",
            "technologies": [
                {
                    "id": "1",
                    "techno": "html"
                },
                {
                    "id": "2",
                    "techno": "css"
                },
                {
                    "id": "3",
                    "techno": "jquery"
                }
            ]
        },
        {
            "name": "ESO AiO",
            "gitlabLink": "",
            "technologies":[
                {
                    "id": "1",
                    "techno": "html"
                },
                {
                    "id": "2",
                    "techno": "css"
                },
                {
                    "id": "3",
                    "techno": "bootstrap"
                }
            ]
        },
Yuusuke
  • 18
  • 8

1 Answers1

1

You can do it this way in React.

import React from 'react';
import listProjects from "./JSONdata/projects.json"
export default function Project(){
    return(
        <div className="projectList">
        {listProjects.projects.map((project, index) => (
            <displayProject project={project} key={index} />
        ))}
        </div>
    )
}

function displayProject({project} ){
    return(
        <>
            <div className="projectContainer">
                <div className="imgContainer">
                </div>
                <div className="nameProject">
                    <a href={project.gitlabLink}><p>{project.name}</p></a>
                </div>
                <div className="technologiesProject">
                    {
                        project.technologies.map(({techno, id}, index) =>(
                            <div className={`${techno}Container`} key={index }>
                                <p>{techno}</p>
                            </div>

                        ))
                    }
                </div>
            </div>
        </>
    )
} 
crispengari
  • 7,901
  • 7
  • 45
  • 53