makeomatic/redux-connect

Add documentation

Open

#95 ouverte le 9 déc. 2016

Voir sur GitHub
 (4 commentaires) (3 réactions) (0 assignés)JavaScript (73 forks)batch import
help wanted

Métriques du dépôt

Stars
 (550 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

Hi,

As a reference for others, I think it would be helpful to add the following example to the readme.

// ./containers/User.js
import { asyncConnect } from 'redux-connect'
import { loadUserSession } from '../actionCreators/session'
import User from '../components/User'

const mapStateToProps = (state, ownProps) => {
	// ... as per redux docs
};

const mapDispatchToProps = (dispatch/*, ownProps*/) => {
	// ... as per redux docs
};

const preloadDataActions = [{
        // dispatch actions here required to preload data for the component to render
	promise: ({ params, store: { dispatch }, location }) => {
		return dispatch(loadUserSession(params));
	}
}];

export default asyncConnect(
	preloadDataActions,
	mapStateToProps,
	mapDispatchToProps
)(User);

This approach allows you to isolate all redux related behaviors to a container, without the need to pollute the component code.

IMHO, i think this is a cleaner approach then using the decorator pattern. Helpful if you want to use packaged components without access to the component source.

Want me to submit a PR?

Adam.

Guide contributeur