我收到这个错误:
./src/components/Playing.jsx Line 15: 'aaa' is not defined no-undef
在我的 Playing.jsx 中:
import React, { Component } from 'react'
console.log(aaa);
来 self 的 Token.jsx
import { connect } from 'react-redux'
imports { Playing } from '../components/Playing'
const mapStateToProps = state => ({
aaa: "asdf"
})
export default connect(mapStateToProps)(Playing)
最佳答案
您不能只在文件中的任何地方console.log()
;它需要在 Playing
组件的某些功能内;而且它也只能通过 props
获得,例如
class Playing extends React.Component {
componentDidMount() {
console.log(this.props.aaa);
}
render() {
return <span>Playing</span>;
}
}
关于javascript - mapStateToProps 和变量未定义 React-Redux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50661826/