Sha256: d5cc86f7c90cb23e6f27a5c485ab6b4168e0ebc351c8748e2fa7992da4b402bd
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
import React, { PropTypes } from 'react'; import HelloWorldWidget from '../components/HelloWorldWidget'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import Immutable from 'immutable'; import * as helloWorldActionCreators from '../actions/helloWorldActionCreators'; function select(state) { // Which part of the Redux global state does our component want to receive as props? // Note the use of `$$` to prefix the property name because the value is of type Immutable.js return { $$helloWorldStore: state.$$helloWorldStore }; } // Simple example of a React "smart" component class HelloWorld extends React.Component { static propTypes = { dispatch: PropTypes.func.isRequired, // This corresponds to the value used in function select above. $$helloWorldStore: PropTypes.instanceOf(Immutable.Map).isRequired, }; constructor(props, context) { super(props, context); } render() { const { dispatch, $$helloWorldStore } = this.props; const actions = bindActionCreators(helloWorldActionCreators, dispatch); // This uses the ES2015 spread operator to pass properties as it is more DRY // This is equivalent to: // <HelloWorldWidget $$helloWorldStore={$$helloWorldStore} actions={actions} /> return ( <HelloWorldWidget {...{ $$helloWorldStore, actions }} /> ); } } // Don't forget to actually use connect! // Note that we don't export HelloWorld, but the redux "connected" version of it. // See https://github.com/rackt/react-redux/blob/master/docs/api.md#examples export default connect(select)(HelloWorld);
Version data entries
2 entries across 2 versions & 1 rubygems