score:13
Try:
import { default as logo } from '../logo.svg';
and use as source in a node of type img, like this:
<img src={logo} />
score:0
You could do it like so
import React from 'react';
import logo from './logo.png'; // Tell webpack this JS file uses this image
console.log(logo); // /logo.84287d09.png
function Header() {
// Import result is the URL of your image
return <img src={logo} alt="Logo" />;
}
export default Header;
score:0
I checked, only create-react-app could use SVG as a component
https://create-react-app.dev/docs/adding-images-fonts-and-files/#adding-svgs
Note: this feature is available with react-scripts@2.0.0 and higher, and react@16.3.0 and higher.
score:2
I had same problem, for some it was how i imported them so I resolved this by using:
import {ReactComponent as Icon} from 'pathtoyourfile.svg
then use as:
<Icon />
Other times however, and I have fallen foul to this a few times, SVG's often have similar class and id names, so if you check the file you might see clip0, image0, pattern0 etc. If you have multiple svg's good chance the ID's and Class names are clashing and are overriding each other. For me the easiest solution was to change the naming convention manually, not sure if a more automated solution exists?
score:4
I had the same exact issue and wrapping the logo component in an svg tag or div made it render on to the screen for me. I can also change the SVG color by setting it from the logo as well.
import { ReactComponent as Logo} from '../logo.svg'
<svg><Logo fill="blue" width="100%" height="100%" /></svg>
// or...
<div><Logo fill="blue" width="100%" height="100%" /></div>
Without the <svg>
or <div>
tag wrapped around it, it was rendering a blank image, taking up the space and all but no visuals. Once I added the wrapper tag around it, it worked. I like this approach since you can dynamically change the SVG styling based on user input.
Source: stackoverflow.com
Related Query
- React SVG import as a Component does not render
- React router dom redirect problem. Changes url, does not render component
- React Router does not render Component
- React URL changes but component does not render
- Why does react component do not re render after changing state
- React router dom changes url, does not render component
- React Redirect with props does not render final component
- React Router Redirect does not render the component
- React component does not render with curly brackets
- My react onClick navigate shows URL, but does not render component
- React component does not render
- React - wrapped component does not render
- Functional react component does not re render on button click
- SVG does not render - React
- React Router Dom & Firebase Auth: history.push changes url but does not render new component when called after firebase auth create account
- React Component does not render when clicking CardActionArea from Material UI
- Importing New React Component Compiles But Does Not Render
- react component does not render and it only appears in inspect section
- React Router DOM - Redirect component does not render route properly
- React Router changes route but does not render the component
- Why does my React component not render when using React-Router?
- React Router: Changes URL but does not render component
- Adding a react component to a array in forEach does not render
- React My component does not render on page load
- react functional component does not render
- array.map() does not work as expected to render <li> component in React
- React does not render component to url's that uses dynamic routing
- Functions are not valid as a React child. This may happen if you return a Component instead of from render
- Attempted import error: 'uuid' does not contain a default export (imported as 'uuid') In React
- onFocus and onBlur does not render in react
More Query from same tag
- Checkbox checked with js map
- Render a list of checkboxes from api and sending an update using hooks
- How to pass actions down to the components in redux
- Cordova Android ReactJS
- getServerSideProps access current browser url
- React error when using audio.play() function
- Toggle showing and hiding components in ReactJs
- undefined is not an object (evaluating 'RCTWebSockerManager.connect') -- React Native
- External script not loading on page change
- Only the ID of data is being returned from an HTTP PUT request in Axios
- I want to create an array of non-overlapping random numbers
- Assign className conditionally based on source object property
- (React and Django) Displaying products on the homepage is working fine, but when I click on any particular product, then the rendering is wrong
- Change text on button depending on value of a number - React using Hooks
- How to integrate CoreUI/react with typescript
- How to call an individual modal box component in react?
- Not really getting the useReducer hook
- How do I share state between routes in React-Router?
- Align text to an input field in react
- Posting a json data to my database with axios (using my backend api)
- Initializing and setting Material UI TextField state as a number
- React - How do I give each child component a unique ref?
- Conceptually, how would I approach creating this image in react (text alignment)
- Can I test if a component <Button/> fires a SubmitEvent with React Testing Library without providing a onSubmit handler?
- React cannot index into array
- How can I add a custom attribute to React's HTMLAttributes from a library?
- How to get data using two different state variables in ReactJS?
- How to trigger FileReader's `onloadend` in unit tests?
- How can i pass different props to more than one children component from the parent one in React?
- How to add types to React Table IndeterminateCheckbox method