小编use*_*483的帖子

如何使用Redux正确实现mapStateToProps?

我正在尝试做一些非常简单的事情:每次单击按钮时,此组件中的"当前"值:https://github.com/conorhastings/react-thermometer会增加.

问题是,当我构建时,控制台抛出以下错误:模块构建失败:SyntaxError:意外的令牌,预期((29:11)

在这一行:

function mapStateToProps(state){
Run Code Online (Sandbox Code Playgroud)

这是我的容器的整个代码:

import React, {Component} from 'react';
import Thermometer from "react-thermometer";
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {incrementValue} from '../actions/index';

class Thermo extends Component{
  getValue(){
    return this.props.val;
  }

  render(){
    return(
          <div>
              <Thermometer
                      min={0}
                      max={90}
                      width={10}
                      height={90}
                      backgroundColor={'gray'}
                      fillColor={'pink'}
                      current={this.getValue()}
              />
              <Button onClick={() => this.props.incrementValue(val)}>+</Button>
          </div>
    )
  }

  function mapStateToProps(state){
    return{
      val: state.val
    };
  }

  function matchDispatchToProps(dispatch){
    return bindActionCreators({incrementValue: incrementValue}, dispatch);
  }
}

export default connect(mapStateToProps, matchDispatchToProps)(Thermo);
Run Code Online (Sandbox Code Playgroud)

为了以防万一,这是我的webpack配置:

var path …
Run Code Online (Sandbox Code Playgroud)

reactjs redux

5
推荐指数
1
解决办法
4333
查看次数

标签 统计

reactjs ×1

redux ×1