Array of Images ReactJs responsive carousel

Stack Overflow Asked by ljcq 09 on January 1, 2022

I am just getting started with web pages. I am trying to make a function for the react responsive carousel so I can pass an array of images and it renders depending on the number of images, I’ve been trying to run something like this:


import React from 'react';

import Carouselfun from '../components/Carouselfun'

import webs from '../assets/images/proj/website.JPG'
import webs1 from '../assets/images/proj/website1.JPG'
import webs2 from '../assets/images/proj/website2.JPG'

const imagess= [webs,webs1,webs2];

function WebsitePage(props) {
        <div className="g-background-pages">


export default WebsitePage;


import React from 'react';
import {Jumbotron, Container, Row, Col, Image} from 'react-bootstrap';

import "react-responsive-carousel/lib/styles/carousel.min.css"; // requires a loader
import { Carousel } from 'react-responsive-carousel';

function carouselfun(props){
                            {props.imag}.forEach(element => {
                                <Image src= element/>

export default carouselfun;

Is there something wrong in the way I am passing my arrays of Images?
or does it have to be with the render function?

Thank you

One Answer

It seems that you are using array.forEach, where a operation will do instead. Map will transform your array and return an array of <div><Image src={element}/> </div> (ReactNodes). Foreach wont return anything. As Talmacel notes in the comment you were missing some brackets too.

Answered by MaxGDN on January 1, 2022

Add your own answers!

Related Questions

std::map::operator[] is more efficient than std::map::insert?

1  Asked on December 27, 2020 by eddieipeace


Splitting a list (?)

1  Asked on December 27, 2020 by superannuated


Python Scrapy how to save data in different files

1  Asked on December 27, 2020 by silver-flash


JS get random value from array and update array

2  Asked on December 27, 2020 by nicolas-schmit


Caught and declared exception in Java?

1  Asked on December 26, 2020 by hrvoje-t


IEnumerable and Recursion using yield return

8  Asked on December 26, 2020 by jamie-dixon


How to parse CSV with node.js?

2  Asked on December 26, 2020 by idarosa


Why this program with for loop give zero when y>5 and x=2

2  Asked on December 26, 2020 by vms


Null pointer exception. How my connection object is pointing to null

2  Asked on December 26, 2020 by monisha-ravi


How do I make contents in HTML by using css

0  Asked on December 26, 2020 by jaeseo-lee


How to show Toaster after logout

2  Asked on December 26, 2020


How to write to a csv within a pandas UDF in pyspark?

0  Asked on December 26, 2020 by codemaster2020


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP