mianmalife / notebook

记录一下
2 stars 0 forks source link

react,redux,react-redux,react-thunk #12

Open mianmalife opened 4 years ago

mianmalife commented 4 years ago

`import React from "react"; import { render } from "react-dom"; import thunk from "redux-thunk"; import { createStore, applyMiddleware } from "redux"; import { Provider } from "react-redux"; import Counter from "./Counter"; import "./index.css";

const initialState = { count: 0 };

function reducer(state = initialState, action) { //接收state,action ==> newState reducer 绝不能返回 undefined switch (action.type) { case "INCREMENT": return { count: state.count + 1 }; case "DECREMENT": return { count: state.count ? state.count - 1 : 0 }; case "RESET": return { count: 0 }; default: return state; } } const store = createStore(reducer, applyMiddleware(thunk));

const App = () => (

);

render(, document.getElementById("root")); `

mianmalife commented 4 years ago

https://codesandbox.io/s/funny-lake-kgqvj