Search code examples
javascriptreactjsweb-componentparceljs

How to add image in react by using parcel?


I have been trying to add image in react. I'm not using webpack, I'm using parceljs. Also using typescript I have try:

import image from path/to/image.png <img src={image} />

inside react component:

try: <img src="path/to/image.png" />

try: <img src={"path/to/image.png"} />

Still, doesn't work.

code look sort of like this:

import * as React from 'react';

const componentName = () => (
  <div>
     <img src="path/to/image.png" />
  </div>
);

Solution

  • You need to do it like this

    import image from 'path/to/image.png';
    

    And then inside your react JSX follow below code:

    <img src={image} />