How to use svg from the folder path in appendchild method javascript or reactjs?

前端 未结 3 2056
别那么骄傲
别那么骄傲 2021-01-24 01:11

i am new to reactjs and i stuck with appending svg element to the div element.

What is that i want to implement? I have a div element created dynamically like below.

3条回答
  •  醉话见心
    2021-01-24 01:54

    From the create-react-app

    One way to add SVG files was described in the section above. You can also import SVGs directly as React components. You can use either of the two approaches. In your code it would look like this:

    import { ReactComponent as Logo } from './logo.svg';
    const App = () => (
      
    {/* Logo is an actual React component */}
    );

    This will load the svg as component and you can use it.

    Full Read here

提交回复
热议问题