[React] 리덕스 툴킷

KoEunseo·2022년 11월 15일
0

파헤쳐보자

목록 보기
14/31

Redux

import {crateStore} from 'redux'
import {Proveder, useSelector, useDispatch} from 'react-redux';
function reducer(state, action) {
  if(action.type === 'up'){
    return {...state, calue:state.value + action.step}
  }
  return state;
}
const initialState = {value: 0}
const store = createStore(reducer, initialState);
const Counter = () => {
  const dispatch = useDispatch();
  const count =useSelector(state=> state.value);
  return <div>
    <buttononClick={()=>{
      dispatch({type:'up', step:2})
    }}>+</button> {count}
  </div>
}
export default function App() {
  return (
    <Provider store={store}>
      <div>
        <Counter></Counter>
      </div>
    <Provider>
  )
}

Redux toolkit

profile
주니어 플러터 개발자의 고군분투기

0개의 댓글