我在行動以下功能無法調用咖喱功能從componentDidMount()的陣營組成
export const fetchDeviceData = (deviceData: Object): ThunkAction => (dispatch: Dispatch, getState: GetState, axios: any) => {
console.log('inside fetchDeviceData', deviceData);
return dispatch(fetchDeviceDataAPI(axios, url, deviceData));
};
,我把它叫做以下列方式在componentDidMount()塊在我的組件
// type declaration (imported from a separate file)
export type DeviceReg = {
[deviceData: Object]: {
readyStatus: string,
err: any,
payload: Object,
}
};
// Prop type declaration
type Props = {
device_reg: DeviceRegType,
fetchDeviceData:() => void,
}
componentDidMount() {
const x = this.getDeviceData();
console.log('header mount mobile', x);
action.fetchDeviceData(x);
}
// The connector
const connector: Connector<{}, Props> = connect(
({ device_reg }: Reducer) => ({ device_reg }),
(dispatch: Dispatch) => ({
fetchDeviceData: (deviceData) => dispatch(action.fetchDeviceData(deviceData)),
}),
);
export default Header;
問題是,當我在函數中包含參數dispatch: Dispatch, getState: GetState, axios: any
時,fetchDeviceData(x)函數沒有被調用,但它在其他方面起作用。導入和依賴關係不是問題,因爲我已經驗證了它們的加載次數。
任何建議,提示或解決方案將有很大的幫助。如果您需要關於我的問題的任何澄清或背景,請告訴我。
在此先感謝。
你可以分享你如何'connect'你的組件
axios
說法? – thedude在編輯中包含了一些額外的細節。請看一下。 – Deepank
看起來像你應該調用this.props.fetchDeviceData(...) – thedude