async-props
async-props copied to clipboard
Using async-props with Alt.js
Since the HoC or AltContainer wraps your component and makes it impossible to call any static method on your component you have to use a util from alt called statics
import connectToStores from 'alt-utils/lib/connectToStores';
import statics from 'alt-utils/lib/statics';
class SomeComponent extends React.Component{
static getStores() {
return [SomeStore]
}
static getPropsFromStores() {
return SomeStore.getState()
}
render(){
return ....
}
}
//declare your functions as constants
const loadProps = (params, cb) => {
cb(null, {
tacos: [ 'Pollo', 'Carnitas' ]
})
}
//pass them to statics first param (used ES6 desctructor)
export default statics(
{ loadAsyncData },
connectToStores(WorkflowPage)
);
Two things:
-
statics
is no longer a thing with current alt.js. - You declare the constant as
loadProps
but exportloadAsyncData