??? : default로 불러오는거랑 component로 불러오는거랑 머가 다름?😯
export { ReactComponent as IcSearch } from './icon_search.svg';
export { default as icPlus } from './icon_plus.svg';
<StIcon src={icPlus} />
icPlus
는 url이라서 src
속성에 넣어주면 img로 사용할 수 있다.(주영언니가 알려줬다)const StSearchIcon = styled(IcSearch)`
position: absolute;
top: 16px;
left: 14px;
`;
솝커톤에서 시간에 따라 아침, 낮, 밤마다 변경되는 3가지 배경화면을 구현해야 했다.
import MorningBackground from "component/common/assets/images/mainBackground_morning.svg";
import DayTimeBackground from "component/common/assets/images/mainBackground_daytime.svg";
import NightBackground from "component/common/assets/images/mainBackground_night.svg";
const [background, setBackground] = useState("");
useEffect(() => {
onChangeBackgroundByTime();
}, []);
const onChangeBackgroundByTime = () => {
const currentTime = new Date().getHours();
if (currentTime >= 0 && currentTime <= 7) {
//새벽
setBackground(NightBackground);
} else if (currentTime >= 8 && currentTime <= 15) {
//낮
setBackground(MorningBackground);
} else {
//밤
setBackground(DayTimeBackground);
}
};
return (
<StyledRoot url={background}>
<StyledMain>{children}</StyledMain>
</StyledRoot>
);
const StyledRoot = styled.div`
display: flex;
flex-direction: column;
align-items: center;
width: 100vw;
min-height: 100vh;
background-image: ${(props) => `url(${props.url})`};
`;
이 글 읽고 svg랑 절친 됐어요 👩🏻🤝👩🏻