redux reducer没有叫

时间:2016-11-01 17:06:18

标签: redux react-redux

有人可以帮我弄清楚为什么这个简单的redux实现没有在锚标记点击上调用reducer?

每次点击都会启动操作,而程序启动时只会减少一次。

任何指针都被贴上了。

// action
const changeText = (text) => {
    console.log('action changeDate')
    return {
      type: 'CHANGE_TEXT',
      text
    };
};

// reducer
const changeTextReducer = (state = [], action) => {
  console.log('reducer changeTextReducer')
  return [
      ...state,
    {
      text: 'Some Text'
    }
  ]

}


class Sales extends React.Component {
  constructor(props) {
    super(props);

    this.handleClick = this.handleClick.bind(this)

  }

  handleClick(e) {
    e.preventDefault();
    this.props.onClick('test')

  }

  render() {
    return (
      <div className="content">
          <a href="" onClick={(e) => this.handleClick(e)} > click me </a>
      </div>

    );
  }
}

const mapStateToProps = (state) => {
  console.log('mapStateToProps', state)
  return {changeTextReducer: state.text}
};

const mapDispatchToProps = (dispatch) => {
  return {
    onClick: (dates) => {
      dispatch(changeText(dates))
    }
  }
};

const SalesApp = connect(
  mapStateToProps,
  mapDispatchToProps
)(Sales);

export default SalesApp



// store
const store = createStore(
    allReducers, composeWithDevTools(
        applyMiddleware(
            thunkMiddleware, // lets us dispatch() functions
            createLogger // neat middleware that logs actions
        ),

    )
);

0 个答案:

没有答案
相关问题