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 :: js two value from array after reduce 
Javascript :: javascript check if undefined or null or empty string 
Javascript :: for loop on object js 
Javascript :: json to array javascript 
Javascript :: mongoose get value 
Javascript :: js difference between two arrays of objects 
Javascript :: javascript set color in hex 
Javascript :: change version webpack-dev-middleware 
Javascript :: node js log colors 
Javascript :: using fb login with angular app 
Javascript :: react native Setting a timer for a long period of time 
Javascript :: on button click show collapse div jquery 
Javascript :: chart js donut 
Javascript :: export html table to excel 
Javascript :: axios defaults headers common 
Javascript :: react hook form clear form 
Javascript :: make 2div in row react js 
Javascript :: Javascript object convert into JSON 
Javascript :: react class components 
Javascript :: one component to another component in vuejs trigger function 
Javascript :: javascript basic function 
Javascript :: js object.entries with sort 
Javascript :: bootstrap multiselect dropdown with checkbox 
Javascript :: destructuring an object js 
Javascript :: js output to console 
Javascript :: angular property value does not exist on type Event 
Javascript :: learn express 
Javascript :: how to get variable from url in javascript 
Javascript :: selected value 
Javascript :: byte number to array js 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =