Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
How to print array data using map method in React JS?

Hello Community I am stuck at some point I am new at React JS. I want to call image file using map function. Only images not appear on the webpage.

Here is my Array.jsx file

const PhotoData = [
   
        {
            imgsrc: gallery_1
        },
        {
            imgsrc: gallery_4
        },
        {
            imgsrc: gallery_7
        },
        {
            imgsrc: gallery_10
        }
    ]

    const PhotoData1 = [
   
        {
            imgsrc: gallery_2
        },
        {
            imgsrc: gallery_6
        },
        {
            imgsrc: gallery_8
        },
        {
            imgsrc: gallery_12
        }
    ]

    const PhotoData2 = [
   
        {
            imgsrc: gallery_3
        },
        {
            imgsrc: gallery_5
        },
        {
            imgsrc: gallery_9
        },
        {
            imgsrc: gallery_11
        }
    ]

    export default [PhotoData,PhotoData1,PhotoData2];

also import the gallery images on above the code.

Here is my photos.jsx file where I write the code.

<div className='photo__header-grid'>
                <div className='grid-item'>
                    {
                        PhotoData.map((val,index)=>{
                            return(
                                <div className='gallery-item' key={index}>
                                    <img src={val.imgsrc} alt="gallery_1"/>
                                </div>
                            )
                        })
                    }
                </div>
            </div>

            <div className='photo__header-grid-1'>
                <div className='grid-item'>
                {
                        PhotoData1.map((val,index)=>{
                            return(
                                <div className='gallery-item' key={index}>
                                    <img src={val.imgsrc} alt="gallery_1"/>
                                </div>
                            )
                        })
                    }
                </div>
            </div>

            <div className='photo__header-grid-2'>
                <div className='grid-item'> 

                    {
                        PhotoData2.map((val,index)=>{
                            return(
                                <div className='gallery-item' key={index}>
                                    <img src={val.imgsrc} alt="gallery_1"/>
                                </div>
                                )
                            })
                    }
                </div>
            </div>

Images not appear on the web-page. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Add this to Array.jsx file

const PhotoData = [
  {
    imgsrc: gallery_1
  },
  {
    imgsrc: gallery_4
  },
  {
    imgsrc: gallery_7
  },
  {
    imgsrc: gallery_10
  }
];

const PhotoData1 = [
  {
    imgsrc: gallery_2
  },
  {
    imgsrc: gallery_6
  },
  {
    imgsrc: gallery_8
  },
  {
    imgsrc: gallery_12
  }
];

const PhotoData2 = [
  {
    imgsrc: gallery_3
  },
  {
    imgsrc: gallery_5
  },
  {
    imgsrc: gallery_9
  },
  {
    imgsrc: gallery_11
  }
];

export default { PhotoData, PhotoData1, PhotoData2 };

Then import it to photos.jsx file

import { FC } from 'react';

import { PhotoData, PhotoData1, PhotoData2 } from './Array.jsx'; // location of the array.jsx file

const Photos: FC = () => {
  return (
    <>
      <div className="photo__header-grid">
        <div className="grid-item">
          {PhotoData.map((val, index) => {
            return (
              <div className="gallery-item" key="{index}">
                <img src={val.imgsrc} alt="gallery_1" />
              </div>
            );
          })}
        </div>
      </div>

      <div className="photo__header-grid-1">
        <div className="grid-item">
          {PhotoData1.map((val, index) => {
            return (
              <div className="gallery-item" key="{index}">
                <img src={val.imgsrc} alt="gallery_1" />
              </div>
            );
          })}
        </div>
      </div>

      <div className="photo__header-grid-2">
        <div className="grid-item">
          {PhotoData2.map((val, index) => {
            return (
              <div className="gallery-item" key="{index}">
                <img src={val.imgsrc} alt="gallery_1" />
              </div>
            );
          })}
        </div>
      </div>
    </>
  );
};

export default Photos;

about 4 years ago · Juan Pablo Isaza Report

0

I don't understand if the images are local or by a link, but if they are local, try using src={require(val.imgsrc)}, as said here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!