reactjsimagegallerygatsbyreact-image

Is this only possible with external URLs and not local?


I'm trying to make a photo gallery using react-images, the URLs are correct but the photos themselves are not loading into my web app. I get the broken image icon when switching themodalIsOpen:false to true.

Ive tried looking up examples of the same problems and alternatives, like if the component was configured right or if I am extending it right in the class.

import React, { Component } from 'react';
import Carousel, { Modal, ModalGateway } from 'react-images';

import blksmith from '../images/gallery/illustration/Blacksmith.jpg';
import mage from '../images/gallery/illustration/Mage.jpg';
const images =
[
    {
        src:{blksmith}

    } ,
    {
        src:{mage}
    }

];
class illuGallery extends Component {
    state = { modalIsOpen: false }
    toggleModal = () => {
      this.setState(state => ({ modalIsOpen: !state.modalIsOpen }));
    }
    render() {
      const { modalIsOpen } = this.state;

      return (
        <ModalGateway>
          {modalIsOpen ? (
            <Modal onClose={this.toggleModal}>
              <Carousel 

                views={images} 
              />
            </Modal>
          ) : null}
        </ModalGateway>
      );
    }
  }
export default illuGallery;

This is in the actual gallery.js file, the web page that renders the gallery.

import React from 'react';
import Layout from "../components/layout";
import IlluPhotos from "../components/illustrationGallery";
import SEO from "../components/seo";
import './gallery.scss';


const GalleryPage = () => {
    return (
        <Layout>
            <div style={{width:'100%',height:'250px'}}>
                <SEO title="Gallery" />
                <IlluPhotos/>


            </div>
        </Layout>
    )
}
export default GalleryPage;

I am seeking some feedback on how to get this to work and what I did wrong, or what I should explore more.


Solution

  • So I ended up adding the pictures I wanted for the gallery to the public folder as mentioned farther down in this post

    Since the https://localhost:8000 was appearing in front of the links to the images I wanted to use.

    Thank you all for helping me find the answer!!