如何将道具传递给多个哑组件 - redux / reactJs?

时间:2016-10-21 22:53:39

标签: reactjs redux

我使用以下代码将数据传递给react组件。我试图找出一种方法将数据传递给多个哑反应组件,但不知道如何实现这一点。有人能告诉我如何将道具传递给多个反应(哑)组件吗?

import React, { Component } from 'react';
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import Results from '../components/displayResults';


@connect(
  state => ({results: state.results})
)
export default class  extends Component {
  render () {
    return <Results  { ...this.props }/>;
  }
}

1 个答案:

答案 0 :(得分:2)

以下解决方案似乎工作正常。

....
import Results from '../components/displayResults';
import Sample from '../components/sample';

    @connect(
      state => ({results: state.results})
    )
    export default class extends Component {
      render () {
        return(
        <div>
        <Results  { ...this.props }/>
        <Sample  { ...this.props }/>
        </div>
      )
      }
    }