Portfolio react js mapping error for project cards.

huangapple go评论60阅读模式
英文:

Portfolio react js mapping error for project cards

问题

以下是代码的翻译部分:

import React from 'react'
import net from '../assets/netflix.png'

const Porfolio = () => {

  const Projects = [
    {
      id:1,
      title:"Netflix Clone",
      desc:"Netflix Landing Page Clone using React JS and Tailwind CSS with Authentication Feature using Firebase",
      imgLink:net,
      codeLink:"https://github.com/codegoggins/netflix-clone",
      projectLink:"https://netflix-clone-13127.firebaseapp.com/"
    }
  ]

  return (
    <div 
    className='px-20 py-4'>
        <p
        className='text-white text-4xl'
        >Projects</p>
        {/* PROJECT CARDS */}
        <div
        className='mt-8 flex flex-col justify-center items-center md:flex md:items-start'
        >
        {
          Projects.map(({id, title, desc, imgLink, codeLink, projectLink}) => (
            <>
            {/* SINGLE CARD */}
            <div className='w-[340px] h-auto relative group md:w-[500px]'>
              {/* OVERLAY */}
               <div 
               className='bg-black/80 text-sm md:text-lg absolute flex top-0 bottom-0 h-full w-full rounded-lg overflow-hidden opacity-0 group-hover:opacity-100 transition-all duration-300'>
               {/* PROJECT DETAILS */}
               <div 
               className='text-white text-sm md:text-lg flex flex-col p-4 gap-3 md:gap-2 items-center justify-center'>
               {/* TITLE */}
               <p>{title}</p>
               {/* DETAIL */}
               <p>{desc}</p>
               {/* BUTTONS */}
               <div 
               className='flex gap-3 text-sm md:text-lg'>
                  <button
                  className='cursor-pointer font-semibold p-1.5 px-4 rounded-md bg-white text-black transition ease-linear duration-300'
                  >
                    <a href={codeLink} target='_blank' rel="noreferrer">Code</a>
                  </button>
                  <button
                  className='cursor-pointer font-semibold p-1.5 px-2 rounded-md bg-white text-black transition ease-linear duration-300'
                  >
                    <a href={projectLink} target='_blank' rel="noreferrer">See Project</a>
                  </button>
               </div>
               </div>
               </div>
               {/* Image */}
               <div className='rounded-lg overflow-hidden'>
               <img src={imgLink} alt="" className='h-full w-full object-cover'/>
               </div>
            </div>
            </>
          ))
        }

        </div>
    </div>
  )
}

export default Porfolio

请注意,这部分代码是React代码,涉及到UI元素和交互,翻译时不包括代码中的注释和HTML/JSX标签名称。如果您有任何其他问题,请随时提出。

英文:
    import React from &#39;react&#39;
import net from &#39;../assets/netflix.png&#39;
const Porfolio = () =&gt; {
const Projects = [
{
id:1,
title:&quot;Netflix Clone&quot;,
desc:&quot;Netflix Landing Page Clone using React JS and Tailwind CSS with Authentication Feature using Firebase&quot;,
imgLink:net,
codeLink:&quot;https://github.com/codegoggins/netflix-clone&quot;,
projectLink:&quot;https://netflix-clone-13127.firebaseapp.com/&quot;
}
]
return (
&lt;div 
className=&#39;px-20 py-4&#39;&gt;
&lt;p
className=&#39;text-white text-4xl&#39;
&gt;Projects&lt;/p&gt;
{/* PROJECT CARDS */}
&lt;div
className=&#39;mt-8 flex flex-col justify-center items-center md:flex md:items-start&#39;
&gt;
{
Projects.map(({id,title,desc,imgLink,codeLink,projectLink})=&gt;(
&lt;&gt;
{/* SINGLE CARD */}
&lt;div className=&#39;w-[340px] h-auto relative group md:w-[500px]&#39;&gt;
{/* OVERLAY */}
&lt;div 
className=&#39;bg-black/80 text-sm md:text-lg absolute flex top-0 bottom-0 h-full w-full rounded-lg overflow-hidden opacity-0 group-hover:opacity-100 transition-all duration-300&#39;&gt;
{/* PROJECT DETAILS */}
&lt;div 
className=&#39;text-white text-sm md:text-lg flex flex-col p-4 gap-3 md:gap-2 items-center justify-center&#39;&gt;
{/* TITLE */}
&lt;p&gt;{title}&lt;/p&gt;
{/* DETAIL */}
&lt;p&gt;{desc}&lt;/p&gt;
{/* BUTTONS */}
&lt;div 
className=&#39;flex gap-3 text-sm md:text-lg&#39;&gt;
&lt;button
className=&#39;cursor-pointer font-semibold p-1.5 px-4 rounded-md bg-white text-black transition ease-linear duration-300&#39;
&gt;
&lt;a href={codeLink} target=&#39;_blank&#39; rel=&quot;noreferrer&quot;&gt;Code&lt;/a&gt;
&lt;/button&gt;
&lt;button
className=&#39;cursor-pointer font-semibold p-1.5 px-2 rounded-md bg-white text-black transition ease-linear duration-300&#39;&gt;
&lt;a href={projectLink} target=&#39;_blank&#39; rel=&quot;noreferrer&quot;&gt;See Project&lt;/a&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
{/* Image */}
&lt;div className=&#39;rounded-lg overflow-hidden&#39;&gt;
&lt;img src={imgLink} alt=&quot;&quot; className=&#39;h-full w-full object-cover&#39;/&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/&gt;
))
}
&lt;/div&gt;
&lt;/div&gt;
)
}
export default Porfolio

> I am getting error to add key , for that instead of react fragments, I
> replace it with a div and give key to it but I am getting error. With
> react fragments I don't get any error but I can't add key to it for
> mapping.
>
> I want the card details to be mapped on all the cards.
enter image description here

答案1

得分: 0

你可以添加:

<React.Fragment key={id}>
    some code
</React.Fragment>

或者移除该片段,将 key 添加到映射中的第一个 div 元素内。

英文:

You can add:

&lt;React.Fragment key={id}&gt;
some code
&lt;/React.Fragment&gt;

or remove the fragment and add the key to the first div inside the map

答案2

得分: 0

你应该在映射内部返回,并为根元素提供一个键。

例如,

{
  products?.map(({ id, title, desc, imgLink, codeLink, projectLink }) => {
    return (
      <div key={id} className='w-[340px] h-auto relative group md:w-[500px]'>
        //在这里放置你的代码
      </div>
    )
  })
}
英文:

You should return inside mapping and provide a key for the root element.

for example,

{
products?.map(({ id, title, desc, imgLink, codeLink, projectLink }) =&gt; {
return (
&lt;div key={id} className=&#39;w-[340px] h-auto relative group md:w-[500px]&#39;&gt;
//Your code here
&lt;/div&gt;
)
})}

huangapple
  • 本文由 发表于 2023年2月8日 18:12:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75384240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定