I have an array of image urls and I am trying to create a new object which should look like this:
source: { uri: 'http://i.imgur.com/XP2BE7q.jpg' }
So I have used reduce() to do that. Now I want that modified imageArray and assign it state variable called images (which must be an array) but I am getting reference error imageArray not defined why so?
I want to assign newly created imageArray to the state variable, how can I do that? Currently, I am getting reference Error should I move reduce() operation outside the class component.
Code:
export default class ImageView extends Component {
constructor(props) {
super(props);
this.state = {
index: 0,
images: imageArray
};
}
render() {
const imageArray = this.props.images.reduce((acc, images) => {
let temp = {
source: {
uri: images
}
};
acc.push(temp);
return acc;
}, []);
console.log(imageArray);
return <View style={{ flex: 1 }} />;
}
}