0

the js file like

import React from "react";

export default () => (
  <svg
    className="xxx"
    data-testid="ggg"
    width="20"
    height="20"
    viewBox="0 0 20 20"
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
  >
    <path
      d="xxxx"        />
  </svg>
);

how to import this and used in other components?

2 Answers 2

1

Its a normal component:

import MySvg from 'path/to/svg'

<MySvg />
Sign up to request clarification or add additional context in comments.

Comments

0

You should name your component like

import React from "react";

export class SvgIcon extends React.Component {
  render() {
    return (
  <svg
    className="xxx"
    data-testid="ggg"
    width="20"
    height="20"
    viewBox="0 0 20 20"
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
  >
    <path d="xxxx"/>
  </svg>
    )
  }
}

And now you can use it:

<SvgIcon/>

Don't forget import component

import SvgIcon from "*component path*";

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.