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

85
Views
How to transfer data from one file to another in reactjs

i have this array of objects, the thing that i am trying to do is to take the array from the file it's sitting in, and transfer it to another file where i can map the items. This is my code (the formatting and spacing is not on point) :

const Upload = () => {


    const photos = [
        {
            id: new Date().getMilliseconds().toString(),
            imagePath: "url..."
        },
    ];

    return (
    <>
       // Markup ....
    </>
    );
};

And i want to do something like this:

import photos from './COMPONENT_NAME';
const Func = () => {
    return (
      <> {photos.map((item) => <div> code... </div> )} </>
    );

Is there any way to do it?

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

0

You can simply export them.
First, move the list outside of the Upload function and then put export key before the declaration like so.

 export const photos = [
      {
          id: new Date().getMilliseconds().toString(),
          imagePath: "url..."
      },
  ];

const Upload = () => { 


    return (
    <>
       // Markup ....
    </>
    );
};

Then import them.

import { photos } from './COMPONENT_NAME';
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!