在redux connect中加载模块

时间:2016-08-28 16:02:18

标签: reactjs redux react-redux

我正在试图弄清楚我做错了什么,这是方案

为greeting.js

import React, { Component } from 'react';
import { connect } from 'react-redux';
import name from './name';

class SayGreeting extends Component {
  componentDidMount() {
    console.log(name);
  }
  render() {
    return (
      <div>
        Good Morning to you, {name}
      </div>
    )
  }
}

const mapStateToProps = ...
const mapDispatchToProps = ...

const Greeter = connect(
  mapStateToProps,
  mapDispatchToProps
)(SayGreeting)

export default Greeter;

name.js

import React from 'react';

const Name = () => (<div>Yoshie</div>);
export default Name;

当我注销“name”时,它会注销一个connect函数而不是我期望的jsx:

function Connect(props, context) {
    _classCallCheck(this, Connect);

    var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));

    _this.version = versio…

我想知道我做错了什么......谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

你试试这个吗,

编辑:尝试在花括号内导入名称

import {Name} from './name'

class SayGreeting extends Component {
componentDidMount() {
  console.log(name);
}
render() {
  return (
    <div>
      Good Morning to you, <Name/>
    </div>
  )
 }
}