0

I want to use react-image-gallery when structure looks like this:

let images = [{original: '1.jpg', thumbnail: '1.jpg'}, {original: '2.jpg', thumbnail: '2.jpg'}, ... ];

<ImageGallery items={images}/>

In my case:

const somObj = {name: 'some-name', photos: ['/somObj/1.jpg', '/somObj/2.jpg', ...]};

I tried to map like this:

<ImageGallery items={[
somObj.map(item=> ({ original: item, thumbnail: item }) )
]}/>

I've also tried it differently, but it still doesn't work.

2 Answers 2

1

You are mapping at the wrong level

You can only use map on an array so go inside your object and into the photo's array. You also don't need the array brackets around the map since map returns an array already.

<ImageGallery items={somObj.photos.map(item => ({ original: item, thumbnail: item }))}/>
Sign up to request clarification or add additional context in comments.

Comments

0

your someObj is not an array, array is photos inside someObj:

<ImageGallery items={[
somObj.photos.map(item=> { return {original: item, thumbnail: item }})
]}/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.