styled.d.ts
// import original module declarations import 'styled-components'; // and extend them! declare module 'styled-components' { export interface DefaultTheme { textColor: string; bgColor: string; } }
theme.tsx
import { DefaultTheme } from "styled-components"; const lightTheme: DefaultTheme = { bgColor: 'white', textColor: 'black', } const darkTheme: DefaultTheme = { bgColor: 'black', textColor: 'white', } export {lightTheme, darkTheme};
index.tsx
... import { ThemeProvider } from 'styled-components'; import { lightTheme, darkTheme } from './theme'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( <React.StrictMode> <ThemeProvider theme={darkTheme}> <App /> </ThemeProvider> </React.StrictMode> );
App.tsx
import './App.css'; import styled from 'styled-components'; import { useState } from 'react'; const Container = styled.div` background-color: ${props => props.theme.bgColor}; `; const H1 = styled.h1` color: ${props => props.theme.textColor}; `; function App() { return ( <div> <Container> <H1>Hello</H1> </Container> </div> ); } export default App;
참고링크
https://velog.io/@rmaomina/react-router-createBrowerRouter
npm i --force react-router-dom@latest
: 가장 최신 버전 설치
: 단순 페이지 분기를 목적
: 각 페이지를 배열형태로 정의
: Router를 Props 형태로 전달받아 전역 컴포넌트에 제공
useNavigate vs Link
react-query 설치
npm i --force react-query
: 웹 페이지가 새롭게 새로고침이 될 때마다 값을 웹브라우저에 출력시키고 싶을 때 사용하는 리액트 훅
: 특정 시기에 코드를 실행시키기 위해 사용하는 리액트 훅 ->
*특정 시기를 정의하게 만드는 요소: 의존성배열
즐겁게 읽었습니다. 유용한 정보 감사합니다.