React에서 SVG 아이콘을 사용하는 방법은 여러 가지가 있지만, 가장 일반적인 방법은 아래와 같다.
아래는 예시 코드다.
// MyIcon.js
import React from 'react';
import { ReactComponent as MyIconSvg } from './my-icon.svg';
const MyIcon = () => {
return (
<div>
<MyIconSvg />
</div>
);
};
export default MyIcon;
import styled from 'styled-components';
import { ReactComponent as Logo } from './logo.svg';
const StyledSVG = styled(Logo)`
width: 50px;
height: 50px;
fill: #000;
`;