简体   繁体   English

Map 未渲染 ReactJs 道具

[英]Map is not rendering ReactJs PROPS

map is not rendering, I created an array in a component and used props to access, but it's not rendering, someone could help me? map 不渲染,我在组件中创建了一个数组并使用道具访问,但它不渲染,有人可以帮助我吗?

import React from "react";
import poke from '../../assets/poke.png';
import { CardProjetos } from './PortfolioStyled';

    const Portfolio = () => {
      const projects = [
        {
            id: 1,
            image: poke,
            title: 'Pokedex',
            description: ' React com axios para requisição de API do pokemon para listar os pokemons e mostrar tela com detalhes pelo ID',

        }, 
        {
          id: 2,
          image: poke,
          title: 'Test',
          description: 'test is not rendering',

      }
    ]
    return (
          <div>
            <CardProjetos itens={projects} />
          </div>

    )
    }

  export default Portfolio;






const Projetos = ({itens}) => {

  return ( 
    <>
    {itens.map((item) => (
    <div>
          <h1>{item.title}</h1>
          <h1>{item.description}</h1>
    </div>
))}
    </>
   )
}



export default Projetos;

I tried a lot of things, but it simply doesnt render.我尝试了很多东西,但它根本不渲染。 The page is blank.页面是空白的。 I put two codes, the first one I created an array The second is to use this value.我放了两个代码,第一个我创建了一个数组第二个是使用这个值。 I think it's something simple, but I'm not seeing it.我认为这很简单,但我没有看到它。 Could some one help me?有人可以帮我吗?

The components you are passing the itens prop to is called CardProjectos which you are importing on line 3. Projectos as far as I can see is declared but never called within the same file.您将itens属性传递给的组件称为CardProjectos ,您将在第 3 行导入它。据我所知, Projectos已声明但从未在同一文件中调用。

You can check this sandbox if it helps: https://codesandbox.io/s/headless-surf-57se9s?file=/src/Portofolio.js如果有帮助,您可以检查此沙箱: https://codesandbox.io/s/headless-surf-57se9s?file=/src/Portofolio.js

import React from "react";
import poke from '../../assets/poke.png';
import { CardProjetos } from './PortfolioStyled';

const Portfolio = () => {
    const projects = [
        {
            id: 1,
            image: poke,
            title: 'Pokedex',
            description: ' React com axios para requisição de API do pokemon para listar os pokemons e mostrar tela com detalhes pelo ID',

        }, 
        {
          id: 2,
          image: poke,
          title: 'Test',
          description: 'test is not rendering',

      }
    ]
    return ( <CardProjetos items={projects} /> )
}

export default Portfolio;


const Projetos = ({items}) => {

  return (
      {
          items.map((item, index)=>{
              return (
              <div key={index} >
                <h1>{item.title}</h1>
                <h1>{item.description}</h1>
              </div>
              )
          })
      }
   )
}



export default Projetos;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM