2017-02-09 6 views
0

反応還元と一緒に使用したいです。react-geolocatedです。 ブースは '名前付き'輸出を輸出デフォルトので使用します。「接続」と反応還元を掛けよう

反応-Reduxの接続スタッフ

const mapStateToProps = (state) => { 
    return { 
     json: state.json 
    } 
}; 

const mapDispatchToProps = (dispatch) => { 
    return { 
     someLocalMethod:() => dispatch(someRemoteMethod()), 
    } 
}; 

export default connect(mapStateToProps, mapDispatchToProps)(Home) 

反応-geolocated関連コネクトスタッフ

export default geolocated({ 
    positionOptions: { 
    enableHighAccuracy: false, 
    }, 
    userDecisionTimeout: 5000 
})(Home); 

一緒にこれらの二つのエクスポートをマージする方法は何ですか?

答えて

1

これを試してみてください:

//file with geolocated stuff ------------------ 
... 
export default geolocated({ 
    positionOptions: { 
    enableHighAccuracy: false, 
    }, 
    userDecisionTimeout: 5000 
})(Home); 

//file with react-redux connect stuff -------------- 
import geoHome from '/pathToGeolocatedHome'; 
... 
export default connect(mapStateToProps, mapDispatchToProps)(geoHome) 
+0

あなたのソリューションが正常に動作しているようです。私には少し試練の時間を与えてください;) – zappee

+2

これまでに見たことがないならば)、このパターンは、反応を使うときにはかなり一般的です。コンポーネント(HOC)基本的には、基本コンポーネントを改良して機能を追加するための呼び出しを連鎖させるだけです。 facebook [HOC](https://facebook.github.io/react/docs/higher-order-components.html)ガイドをご覧ください。 –

+0

そのHOCパターンは非常にエレガントです。君たちありがとう。 – zappee

0
import connect from 'react-redux-connect'; 
import { actionOne, actionTwo } from './actions'; 
export class MySmartComponent { 
    static mapStateToProps(state, ownProps) { 
     // if you need to map some data from store 
     return { 
      // some data from state here 
}; 
} 
static mapDispatchToProps(dispatch, ownProps) { 
     // if you need to dispatch some actions 
     return { 
kactionOne, 
      actionTwo, 
    }; 
    } 
static mergeProps(stateProps, dispatchProps, ownProps) { 
     // if you want to merge props manually 
     return { 
      // ... 
     } 
    } 
static connectOptions = { 
     // if you want to merge props manually 
     return { 
      // ... 
     } 
    } 
static connectOptions = { 
     // if you want to merge props manually 
     return { 
      // ... 
     } 
    } 
static connectOptions = { 
     // if you need to tweek some connect options 
     // e.g. pure: false 
    }; 
render() { 
     // return something... 
    } 
} 
// and just pass your component to `connect` function 
// all settings will be taken from static props 
export default connect(MySmartComponent); 
関連する問題