How to return or export result of function javascript from service file to use in another file

0

Function Of Service

export const deviceInfoRequest = async (callback) => {
    var request = new DeviceInfoMessage();
    var AuthToken = 'ciOiJIUzI1NiIsInR5cCI6IkpXVCJ9';
    client.deviceInfo(request, {'x-authorization': AuthToken}, (err, response) => {
        var dataDevicename = response.getDevicename();
        var dataDeviceid = response.getDeviceid();
        console.log("DeviceName==>>>>",dataDevicename);     
        console.log("DeviceId==>>>>",dataDeviceid); 
        this.callback(dataDevicename,dataDeviceid);
    });
}

=======> Result of "console.log"=="DeviceName== test" and "DeviceId==>>>> 0xdeadbeef".

Function Of Sagas

function* getDeviceInfo({ payload }) {
    try {
        const deviceInfoData = yield call(deviceInfoRequest, payload);
        console.log("deviceInfoSagasssssssssssssssssssssss", deviceInfoData)
        if (deviceInfoData.status === 200) {
            yield put(showDeviceInfoAction(deviceInfoData.data));
        }
    } catch (error) {

    }
}

=======> Result of "console.log"=="deviceInfoSagasssssssssssssssssssssss undefined"
javascript
reactjs
return
export
asked on Stack Overflow Feb 25, 2020 by wiem khardani • edited Feb 25, 2020 by trixn

1 Answer

0

Well you need to import that function in your "Sagas" function file, try:

import { deviceInfoRequest } from "../PATH_TO_FUNCTION";

Then you can use that function. Also, if you want to evaluate that function just do deviceInfoRequest()

answered on Stack Overflow Feb 25, 2020 by Vicente

User contributions licensed under CC BY-SA 3.0