Javascript 状态更改中的错误

Javascript 状态更改中的错误,javascript,reactjs,redux,redux-form,Javascript,Reactjs,Redux,Redux Form,我在React与Redux合作。我在程序中定义了动作和减速器。我想通过onClick事件更改状态,但它不会更改 这是我的代码: import React, { Component, PropTypes } from 'react'; import { createStore } from 'redux'; const display = (state=0, action) => { switch (action.type){ case 'INCREMENT': r

我在React与Redux合作。我在程序中定义了动作和减速器。我想通过onClick事件更改状态,但它不会更改

这是我的代码:

import React, { Component, PropTypes } from 'react';
import { createStore } from 'redux';

const display = (state=0, action) => {
  switch (action.type){
    case 'INCREMENT':
      return state+1;
    case 'DECREMENT':
      return state-1;
    default:
      return state;
  }
};

const store = createStore(display);

store.dispatch({ type: 'INCREMENT'});

var ReduxApp = React.createClass({

  plus(){
    return store.dispatch({type: 'INCREMENT'});
  },

  minus(){
    return store.dispatch({type: 'DECREMENT'});
  },

  render(){

    return(
      <div>
        <h1>{store.getState()}</h1>
        <button onClick={this.plus}>+</button>
        <button onClick={this.minus}>-</button>
      </div>
    );
  },
});

module.exports = ReduxApp;

store.subscribe(() => render(<ReduxApp />));
import React,{Component,PropTypes}来自'React';
从“redux”导入{createStore};
常量显示=(状态=0,操作)=>{
开关(动作类型){
案例“增量”:
返回状态+1;
“减量”一案:
返回状态-1;
违约:
返回状态;
}
};
const store=createStore(显示);
dispatch({type:'INCREMENT'});
var ReduxApp=React.createClass({
加(){
返回store.dispatch({type:'INCREMENT'});
},
减(){
return store.dispatch({type:'DECREMENT'});
},
render(){
返回(
{store.getState()}
+
-
);
},
});
module.exports=ReduxApp;
订阅(()=>render());

我尝试了subscribe方法&re-rendered,但它不起作用。

您就快到了,您还没有将渲染连接到您的Redux存储,但已经很接近了

要手动连接它,您可以编写如下内容

store.subscribe(() => render(<MyComponent />, document.querySelector('#container'));

在真实场景中,为了将商店连接到react应用程序,您可能会使用react-redux及其提供程序组件之类的东西。

能否显示订阅和重新呈现代码?我编辑了代码。请看@MichelletAlleythe code
store.subscribe()
this.render()
不应在调用它的地方调用。@limelights ok。那我该打电话到哪里?好的,谢谢。我改了密码,请看一下我收到错误“未定义渲染”。复制粘贴代码并不总是有用-将
render
更改为
React.render
。收到错误。如果你能详细说明,这将是有益的-这是一个工作的例子。我不知道您为什么不使用
React.render()
ReactDOM.render
进行渲染。我确实更改了您告诉我的内容。但我仍然得到了这个错误:未捕获错误:不变冲突:_registerComponent(…):目标容器不是DOM元素。
var MyComponent = React.createClass({});
store.subscribe();