【发布时间】:2020-08-18 14:00:02
【问题描述】:
我正在学习 redux,为了调试,我在 Chrome 中安装了他们的调试扩展。除了我的代码不起作用之外,为什么扩展程序不显示存储数据,尽管后者已由 const store = createStore(counter); 初始化?
index.js
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { createStore } from "redux";
import App from "./App";
const store = createStore(counter);
function counter(state = 0, action) {
switch (action.type) {
case "INCREMENT":
return state + 1;
case "DECREMENT":
return state - 1;
default:
return state;
}
}
function App() {
return (
<div>
<p>{store.getState()}</p>
<button onClick={() => store.dispatch({ type: "INCREMENT" })}>
Increment
</button>
</div>
);
}
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
);
Stackblitz:https://stackblitz.com/edit/react-p8vm7h?file=src/index.js
提前谢谢你!
【问题讨论】: