arunoda / react-komposer

Feed data into React components by composing containers.
MIT License
732 stars 70 forks source link

2.X redux help & examples could benefit from improvement #134

Closed stewartcelani closed 7 years ago

stewartcelani commented 7 years ago

The default redux example in migrating from 1.X relies on the env variable which, in its own section, is a little confusing. The myCompose function is created but not used in the following example? Could benefit from some more explanation.

My project relies heavily on react-komposer and 1.X has been awesome and we have been waiting for 2 eagerly since your post about it here so really keen to get it up and running. Amazing work.

I've ported my meteor data loading over with your getTrackerLoader but the getReduxLoader relies on env.reduxStore (the env part of the doc is super confusing to me) and I'm getting onData is not a function. Trying to wrap it like in the example doesn't work either.

Any chance of getting a guide on how to port old style redux functions to the new style?

TypeError: onData is not a function
---
const mapStateToProps = (props, onData) => {
    console.log("App.jsx -> mapStateToProps")
    let state = store.getState()
    onData(null, {...state})
    return store.subscribe(() =>{
        let state = store.getState()
        onData(null, {...state})
    })
}
export default compose(getReduxLoader(mapStateToProps))(App)
arunoda commented 7 years ago

What we need env because that's a way to pass the reduxStore to the dataLoader. (AKA, function pass to the composer). If you have a way to get the store somehow that's not an issue.

As for the above example, you have provided you could simply right it like this:

const mapStateToProps = (props, onData) => {
    console.log("App.jsx -> mapStateToProps")
    let state = store.getState()
    onData(null, {...state})
    return store.subscribe(() =>{
        let state = store.getState()
        onData(null, {...state})
    })
}
export default compose(mapStateToProps)(App)