File path

mainman100 asked 6 years ago

Sounds stupid but I cannot successfully change the external file references in your code to relative local files. I have a file structure of (part only): -assets/images - public -src I change the file path to "/assets/images/[name of image]" On the local server this appears to translate into localhost/3000:/assets/images/[name of image] But no image shows up. What am I doing wrong?

Jakub Mandra staff premium answered 6 years ago

Hello,
It's because React have to compile first, so if you want to use image or something from your local files you have to import that.
And for this case all paths (like your assets) have to be inside /src folder.
In your particular case it should look like this:

Structure:

>src
  >assets
    -image.jpg
  >components
    App.js

Code:

import React, { Component } from 'react';
import image from './../assets/image.jpg';

class App extends Component {
  render(){
    return(
        <div>
            <img src={image}a alt="Your image" />
        >/div>
    );
  }
}

export default App;

Best regards,
Jakub from MDB


mainman100 commented 6 years ago

Many thanks

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No