px을 썼을 때는 사용자가 브라우저 글씨 크기를 바꾸거나 확대비율을 바꿔도 글꼴이 고정값으로 유지된다.
rem을 쓰면 사용자 설정에 맞춰서 크기가 하게 만들 수 있다.
html {
font-size: 62.5%;
/* 62.5% of the base size of 16px = 10px.*/
/* 브라우저의 기본 글씨 크기는 16px이다. 62.5%로 설정하면 기본 설정을 쓰는 유저 기준으로 10px을 기준으로 잡게된다 */
}
body {
font-size: 1.6rem;
/* reset 10*1.6 = 16px, to make sure you do not get any 10px around */
}
Redux Toolkit allows us to write "mutating" logic in reducers. It doesn't actually mutate the state because it uses the Immer library, which detects changes to a "draft state" and produces a brand new immutable state based off those changes
3. useSelector, useDispatch 사용하기
(해당 예시에서는 increment만 불러왔음)
import Head from "next/head";
import Image from "next/image";
import styles from "../styles/Home.module.css";
import { increment } from "../features/counter/counterSlice";
import { useDispatch, useSelector } from "react-redux";
export default function Home() {
const count = useSelector((state) => state.counter.value);
const dispatch = useDispatch();
return (
<div className={styles.container}>
<button onClick={() => dispatch(increment())}>Add</button>
<p>{count}</p>
</div>
);
}
그래서 rtk가 제공하는 두가지 웅요한 API가 있다. 모든 리덕스앱에서 쓰이는 것들인데.
- configureStore
createStore보다 더 쉽다. createStore는 named options parameter가 필요하기 때문이다.
- createSlice
Immer 라이브러리를 사용해서 리듀서를 쓴다. state.value = 123 같이 스프레드 연산자 없이 mutating하는 식으로 코드를 작성할 수 있다.(물론 immutable하게 업데이트 해줌)
그리고 각 리듀서들마다 자동으로 액션 크리에이터 함수, 액션 타입을 만들어준다. (All of the action creators and action types are generated automatically, and the reducer code is shorter and easier to understand.)