0

how can i set const value using mobx obeserve data? as i don't know how can i define props here.

export const BASE_URL = base_url_from_mobx

i have some data in this function. From there i will have some confidential data and a base url. This ApiKeys is a native module

ApiKeys.getApiKeys((data)=>{
    let secureData = JSON.parse(data)
}

i have an api.js file where i set the interceptor and set the base url like below

const api = axios.create({
    baseURL: BASE_URL,
    timeout: 10 * 1000,
    headers: {
        'content-type': 'application/json',
    }
});

here BASE_URL is defined and export as const in constants.js file but now i want to set it from the value i have got from the function. This can be done if i can do like below

const api = axios.create({
    // baseURL: BASE_URL,
    baseURL: (JSON.parse(AsyncStorage.getItem(SECURE_KEY))).SOHOJ_APP_API_BASE_URL_DEVELOPMENT,
    timeout: 10 * 1000,
    headers: {
        'content-type': 'application/json',
    }
});

but it is giving me issue like

enter image description here

how can i do that. my i use to make a request like below using api.js

api
    .post('api_end_point',parameters,headers)
    .then(response=>{

    })
    .catch(error =>{

    })

thanks

Wasi Sadman
  • 1,382
  • 1
  • 15
  • 27

1 Answers1

1

It means that there is some issue with your AsyncStorage.getItem(SECURE_KEY) ,probably it's not a proper json object.do a console.log of AsyncStorage.getItem(SECURE_KEY) and see what value you get.

Sakshi
  • 1,464
  • 2
  • 8
  • 15
  • 1
    paste here the output of the console.log of AsyncStorage.getItem(SECURE_KEY) – Sakshi Dec 19 '20 at 08:27
  • when i do this.. AsyncStorage.getItem(SECURE_KEY).then(value =>{ console.log('SECURE_KEY: ',value) }) i get the data but i cannot do that inside there... please see my const api – Wasi Sadman Dec 19 '20 at 08:34
  • i did not get you ? i am just asking that what output you are getting from AsyncStorage.getItem(SECURE_KEY) ? – Sakshi Dec 19 '20 at 10:26
  • i am getting a json string as a output.. and then i turn it into a json object... but the problem is with promise – Wasi Sadman Dec 19 '20 at 10:46
  • yea so i am saying that to paste the json string output.because error is while parsing that json string. – Sakshi Dec 19 '20 at 11:18