react path to image code example

Example 1: react js image path src from local folder

// Assuming logo.png is in the same folder as JS file
import logo from './logo.png';

// ...later
<img src={logo} alt="logo" />

Example 2: how to write img jsx

<img src={window.location.origin + '/img/myImage.png'} />

Example 3: React import image with url

import React from "react";
 import ReactDOM from "react-dom";

 function App() {
   return (
     <img 
      src="https://images.pexels.com/photos/20787/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=350"
      alt="new"
      />
   );
 }

 const rootElement = document.getElementById("root");
 ReactDOM.render(<App />, rootElement);

Example 4: React import image with url

import React from 'react';
import ReactDOM from 'react-dom';

const App: FunctionComponent = () => {
  return (
    <img src = {this.props.url} alt='something'/> 
  );
}