javascript - mapStateToProps 和变量未定义 React-Redux

标签 javascript html reactjs redux react-redux

我收到这个错误:

./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/

相关文章:

javascript - 在设备中打开数字键盘时出现问题

html - 媒体容器和旁边主要内部或外部

javascript - 如何将百分比值传递给宽度以响应数据网格列

css - 如何使Material UI v1.0 Dialog背景透明?

javascript - 在 jquery each() 迭代器函数中访问 JS 对象

javascript - 每当我在 <head> 部分添加特定脚本时,我都会丢失背景颜色

javascript - 选择选项上的 for 循环不起作用

javascript - 访问 jQuery 中的重复标签

javascript - 使用 setState 设置 react 页面的所有状态

javascript - Vue.js 如何在计算属性中设置观察者?