// configStore.js
import { createStore } from "redux";
import { combineReducers } from "redux";
const rootReducer = combineReducers({});
const store = createStore(rootReducer);
export default store;
// index.js 에 추가한 코드
import store from "./redux/config/configStore";
import { Provider } from "react-redux";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<Provider store={store}>
<App />
</Provider>
);
// 초기 상태값 세팅 (state)
const initialState = {
number: 0,
};
= const [number, setNumber] = useState(0) ← 초기값
// Reducer
const counter = (state = initialState, action) => {
switch (action.type) {
default:
return state;
}
};
export default counter;
= const onClickHandler = () => { setNumber(number + 1) }
// configStore.js
import { createStore } from "redux";
import { combineReducers } from "redux";
import counter from "../modules/counter";
const rootReducer = combineReducers({
counter
});
const store = createStore(rootReducer);
export default store;
const sotre = useSelector((state) => {
return state.counter; // 0
});