async-props icon indicating copy to clipboard operation
async-props copied to clipboard

Using async-props with Alt.js

Open burimshala-zz opened this issue 8 years ago • 1 comments

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)
);

burimshala-zz avatar Apr 20 '16 11:04 burimshala-zz

Two things:

  1. statics is no longer a thing with current alt.js.
  2. You declare the constant as loadProps but export loadAsyncData

itsthatguy avatar May 19 '16 19:05 itsthatguy