React3 [React] useReducer useReducer useReducer is a React Hook that lets you add a reducer to your component. const [state, dispatch] = useReducer(reducer, initialArg, init?) Parameters reducer: The reducer function that specifies how the state gets updated. It must be pure, should take the state and action as arguments, and should return the next state. State and action can be of any types. initialArg: The value from w.. 2023. 11. 30. [React] createContext createContext createContext lets you create a context that components can provide or read. const SomeContext = createContext(defaultValue) Parameters defaultValue: The value that you want the context to have when there is no matching context provider in the tree above the component that reads context. If you don’t have any meaningful default value, specify null. The default value is meant as a “.. 2023. 11. 29. [React] 페이지 이동하기 Next.js에서는 pages 폴더를 통해 접근하는 주소별 컴포넌트(페이지)를 넘겨준다. (SSR 방식) router 변수를 이용하여 이동할 경로를 처리한다. 반면 기본 React에서는 폴더 구조와는 상관없이 네이게이션을 정의해서 사용한다. npm i react-router-dom BrowserRouter를 App루트에 감싸준다. import React from "react"; import ReactDOM from "react-dom/client"; import App from "./App"; import { BrowserRouter } from "react-router-dom"; ReactDOM.createRoot(document.getElementById("root")).render( ); 그리고 A.. 2023. 9. 6. 이전 1 다음