Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

importing svg into react

import React from 'react';
import { ReactComponent as BrandIcon } from "./assets/brand-icon.svg";

export default function(){
  return( 
      <div>
          <BrandIcon />
      </div>
   );
}
Comment

import svg react

import React from 'react';
import LogoName from '../assets/logo.svg'

const Header = () => {
    return ( 
        <div>
           	<img src={LogoName} alt="logo"/>
        </div>
     );
}
Comment

how to import svg in react

//customIcon.js

import React from "react";
import {ReactComponent as ImportedSVG} from "path/to/myIcon.svg";
import { SvgIcon } from '@material-ui/core';

function CustomIcon() {
 return(
  <SvgIcon component={ImportedSVG} viewBox="0 0 384 512"/>

)
}

export default CustomIcon;
Comment

import svg as react component

import React from 'react';
import { ReactComponent as YourSvg } from './YourSvg.svg';

const MyComponent = () => {
    return(
        <YourSvg/>
    );
}

export default MyComponent ;
Comment

Svg as a component react

import React from 'react';
import {ReactComponent as ReactLogo} from './logo.svg';

const App = () => {
  return (
    <div className="App">
      <ReactLogo />
    </div>
  );
}
export default App;
Comment

how to add svg file in react

import YourSvg from "/path/to/image.svg";

const App = () => {
  return (
    <div className="App">
      <img src={YourSvg} alt="Your SVG" />
    </div>
  );
};
export default App;
Comment

add svg in react

<span>
                  <object style={{ float: 'left', height: '15px', position: 'relative', top: '4px' }} data={`${ROOT_URL}/assets/images/svg-icons/history-icon.svg`} type='image/svg+xml'></object>
                </span>
Comment

convert svg to react component

//Use this WEB APP to convert any svg to a valide reactJs or React native Component
Playground - SVGR
https://react-svgr.com/playground/
Comment

PREVIOUS NEXT
Code Example
Javascript :: comma in price js 
Javascript :: check if variable is undefined or null jquery 
Javascript :: javascript get text between two strings 
Javascript :: onclick checkbox hide div and unchecked show div 
Javascript :: react native mac 
Javascript :: component did mount in hooks 
Javascript :: Jquery search in json 
Javascript :: regex pattern to validate email 
Javascript :: js load multiple images 
Javascript :: p5.js add class to button 
Javascript :: for array javascript 
Javascript :: javascript check if element is overflowing 
Javascript :: js indexof nested array 
Javascript :: how to count vowels in a string javascript 
Javascript :: javascript last index 
Javascript :: jquery selected option value 
Javascript :: execute JS code after pressing space bar 
Javascript :: react state add to array 
Javascript :: how to find the last item in a javascript object 
Javascript :: inarray javascript 
Javascript :: atob nodejs 
Javascript :: immutable array sort javascript 
Javascript :: get element by tag name 
Javascript :: react-geocode 
Javascript :: react detect screen size 
Javascript :: javascript hover event 
Javascript :: Matched leaf route at location "/" does not have an element. This means it will render an <Outlet / with a null value by default resulting in an "empty" page. 
Javascript :: react native image source local file 
Javascript :: random id number nodejs 
Javascript :: import { Application } from "express" 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =