question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array's of images

See original GitHub issue

Hello people,

Well, my problem is about images. imagine the problem, that in my div parent, only have tags img children or 1 or more than 1. And i put that img src’s on a array like:

– slider.json –

[
     './img/header.jpg',
     './img/header1.jpg'
]

And this is my React component:

import React, { Component } from 'react';
import * as data from "../resources/slider.json";

class FullWidthHeader extends Component{
    render(){
        return(
           <Image />
        );
    }
}

class Image extends FullWidthHeader{

    createImage(props){
        return(<img src={props} alt="imgwow" />);
    }

    createImages(images){
        return images.map(this.createImage);
    }

    render(){
        return(
            <div>
                { this.createImages(data) }
            </div>
        );
    }
}

export default FullWidthHeader;

My problem i think, its for webpack seeing the img src, i cant see the image… How i can resolve this?

Kind Regards,

Pedro Cruz

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
Timercommented, Jun 16, 2017

webpack isn’t able to analyze this, but the fix should be relatively simple.

Change slider.json to slider.js, and replace entries like so:

export default [
  require('./img/header.jpg'),
  require('./img/header1.jpg')
]

Change

import * as data from "../resources/slider.json";

to

import data from '../resources/slider';
1reaction
Timercommented, Jun 16, 2017

It cannot be done with json unless if you use the public folder. Sorry!

I’ll close this as resolved, since you said the js solution works (and https://github.com/facebookincubator/create-react-app/issues/2545#issuecomment-309015448 for json).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Showing an image from an array of images - Javascript
Just as Diodeus said, you're comparing an Image to a HTMLDomObject . Instead compare their .src attribute: var imgArray = new Array(); ...
Read more >
Arrays and Array Images - Earth Engine - Google Developers
Array Images. Arrays in Earth Engine are constructed from lists of numbers and lists of lists. The degree of nesting determines the number ......
Read more >
Pixels, Arrays, and Images. An Introduction to Computer Vision
Each cell of the array, corresponds to a pixel in the image. This means that the array's dimensions are equal to the resolution....
Read more >
Arrays of Pictures
Reference through an array simplifies naming of the pictures. The image tags on the page are put in an array anyway. (Document.images[]). Mechanics:....
Read more >
Create an Array of Images in JavaScript (Tutorial) - Maker's Aid
The simplest, most straightforward way to create an array of images is to declare an array object and push the URLs to your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found