React Standard 4th 과제
EX2 문제
yarn add styled-components styled-reset
/* 터미널 창에서 패키지 다운*/
import { createGlobalStyle } from "styled-components";
import reset from "styled-reset";
const GlobalStyle = createGlobalStyle`
${reset}
`;
function BoxContainer() {
const [activeIndex, setActiveIndex] = useState(0);
const handleClick = (index) => {
setActiveIndex(index);
};
return (
<Container>
{[0, 1, 2, 3, 4].map((index) => (
<Box
key={index}
active={activeIndex === index}
onClick={() => handleClick(index)}
/>
))}
</Container>
);
const StyledBox = styled.div`
background-color: ${(props) => (props.$active ? "blue" : "gray")};
`;
function Box({ active, onClick }) {
return <StyledBox $active={active} onClick={onClick} />;
}
EX3 문제
function App() {
const [texts, setTexts] = useState(() => {
const savedTexts = localStorage.getItem("texts");
return savedTexts ? JSON.parse(savedTexts) : [];
});
useEffect(() => {
localStorage.setItem("texts", JSON.stringify(texts));
}, [texts]);


