0

I have included this already in my index.html.

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.12/semantic.min.css"></link>

Still no images are displayed.I have for example tech.png in my src folder which contains Sample.js and index.js files.

Here is my Sample.js file:

import React from 'react';
import { Image} from 'semantic-ui-react';
import {Link} from 'react-router-dom';


export default class Sample extends React.Component {
 render(){
   return(
    <Image src='./src/tech.png' href as={Link} to="/Users"/>
   );

 }

Help me to render the image.

6
  • You have just the CSS in CDN, has the semantic library been installed since Image is a component? Commented Mar 2, 2018 at 7:18
  • What is the error that you're getting? Commented Mar 2, 2018 at 7:19
  • Image is not rendered.Semantic-ui is installed Commented Mar 2, 2018 at 7:25
  • can you try the full path instead of ./src/tech.png? Commented Mar 2, 2018 at 10:12
  • 2
    btw you don't need href when using as={Link} Commented Mar 2, 2018 at 10:12

2 Answers 2

4

This should not be a CSS issue. If the CSS was not installed, the markup would still render an img tag with the correct source to display the image. I think what is probably happening is your image is not actually getting included in the build when Webpack runs. By default the /src folder is not getting automatically included into any builds in create-react-app.

For the image to be included you must require() like this:

<Image
  as={Link}
  src={require('./src/tech.png')}
  to='/Users'
/>

That will allow you to reference your image relative to your React component. This isn't an issue with semantic-ui-react.

Sign up to request clarification or add additional context in comments.

Comments

1

I was confused about this too, as the image link of an example in the semantic ui docs looked similiar to yours:

const ImageExampleImage = () => (
  <Image src='/images/wireframe/image.png' size='small' />
)

So I looked the example up on their GitHub, turns out if you want to link to images like that, you have to put them in the public directory of your create-react-app project, then it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.