I am new to react. I want to loop images list(Json) and show these images on screen. So I want to create a prop with Array. But I don't know how to pass Array as props? Would you help take a look?
var images = [
"./resources/bgdefault.jpg",
"./resources/bg1.jpg",
"./resources/bg2.jpg",
"./resources/bg3.jpg",
"./resources/bg4.jpg",
"./resources/bg5.jpg",
"./resources/bg6.jpg",
"./resources/bg7.jpg",
"./resources/bg8.jpg"
];
type State = {
index: number;
};
type Props = {
backgroundDuration: number;
imagePath: Array<string>;
};
export class BackgroundImage extends React.Component<Props, State> {
timerID: number;
constructor(props: Props) {
super(props);
this.state = {
index: -1
};
this.timerID=0;
}
.....
render() {
const path:string = images[this.state.index];
return (
<div
style={{
width: "100%",
height: "100%",
backgroundSize: "cover",
backgroundImage: `url(${path})`
}}
></div>
);
}
}