mapStateToProps和变量未定义React-Redux

时间:2018-06-02 22:50:27

标签: javascript html reactjs redux react-redux

我收到此错误:

  

./ SRC /组件/ Playing.jsx     第15行:' aaa'未定义no-undef

在我的Playing.jsx中:

import React, { Component } from 'react'

console.log(aaa);

来自我的Token.jsx

import { connect } from 'react-redux'
imports { Playing } from '../components/Playing'

const mapStateToProps = state => ({
  aaa: "asdf"
})

export default connect(mapStateToProps)(Playing)

1 个答案:

答案 0 :(得分:2)

您无法在文件中的任何位置console.log();它需要在Playing组件的某个函数内;它也只能通过props提供,例如

class Playing extends React.Component {
  componentDidMount() {
    console.log(this.props.aaa);
  }

  render() {
    return <span>Playing</span>;
  }
}