am trying to run below api in my forge app and getting this error after deployment
const response = await api.asUser().requestJira(route/rest/api/3/field, {
headers: {
‘Accept’: ‘application/json’
}
});
Error:
runtime.js:7 Uncaught (in promise) Error: Forge runtime not found.
at t.getRuntime (runtime.js:7:15)
at fetch.js:12:41
at Object.requestJira (index.js:13:12)
at App.js:65:43
at f (regeneratorRuntime.js:44:17)
at Generator. (regeneratorRuntime.js:125:22)
at Generator.next (regeneratorRuntime.js:69:21)
at h (asyncToGenerator.js:3:20)
at a (asyncToGenerator.js:22:9)
at asyncToGenerator.js:27:7
@AlexeyKotlyarov am now trying to use requestJirs from forge/bridge. it return data in function (can console.log) but when returning in main, it is returning promise object. not sure how to resolve this. also not sure how to read this object. any help is appreciated.
You are setting your initial state with an async function, so the allFields variable will be a Promise. React also won’t wait on that initialiser function before it performs the render, so there’s no guarantee that the promise will have resolved by the time the value is logged.
A more idiomatic approach would be to fetch the data with a useEffect hook, and setting the result of that in a non-Promise state variable.
useEffect function can detect only methods within function App. as requestJira needs to be async; have defined it in top level outside function App. so getCustomFields within useEffect could not detect method
@SuvarnaGaikwad I have tested that it is possible for useEffect to call functions outside of App, since the function should be in global scope. Can you show the error you’re getting?