kunheejeon / frontend-react-sessions

0 stars 0 forks source link

07/10 - 07/14 #2

Open kunheejeon opened 1 year ago

kunheejeon commented 1 year ago

07/10

kunheejeon commented 1 year ago

07/11

setTimeout and promise code questions need to be reviewed.

kunheejeon commented 1 year ago

Redux is a state management system for a cross-component/app-wide state (React 3rd party library)

States: local state: single component => useState()/ useReducer() cross-component state: state that affects multiple components => prop chains / prop drilling app-wide state: state that affect entire app (e.g. user auth status) => useContext() or Redux

React Context vs Redux Context disadvantages: complex setup/management for large code/components

Redux

npm install redux react-redux src/store/index.js as redux folder+file in root index.js file,

import { Provider } from "react-redux";
import store from "./store/index";

useSelector()

useDispatch()

in redux never mutate the existing state, instead override it by returning new state object.

Redux Toolkit createSlice()

configureStore()
const store = configureStore({
  reducer: counterSlice.reducer,
});

core redux concept

kunheejeon commented 1 year ago

Single-Page Application Routing

Generally configure routes make different components are loaded for different paths

To route to other pages

to have nav, have root layout

then put all other pages into children (nested route)

children: [{
  path: 'product',
  element: <product />
}]

handling error page

active link: if the page is rendering the link, link is being active state css

Dynamic Route (use colone : and useParams()) useParams() : params from link

data fetching and submission

deferring data fetching