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?
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';