Cannot get issue summary and description from Jira in Forge

Am working with Forge UI KIT to get issue summary and description from Jira. when I run the code below, it throws error

Error: Error thrown in the snapshot context.
App code snapshot error: Snapshot error occurred: Error: Cannot destructure prop
erty issueKey of ‘undefined’ or ‘null’.
Learn more about the snapshot context at http://go.atlassian.com/forge-snapshot-
context.

Below is the code


//import goes here

// Get the context issue key
  const { platformContext: { issueKey } } = useProductContext();
const fetchIssue = async () => {

    // Fetch issue fields  from Jira
    const issueResponse = await api.asApp().requestJira(`/rest/api/2/issue/${issueKey}?fields=summary,description`);
    await checkResponse('Jira API', issueResponse);
    //const { summary, description } = (await issueResponse.json()).fields;


const data = (await issueResponse.json()).fields;

console.log('Display Issues');
console.log(data.summary);
console.log(data.description);
return data;

};

const App = () => {

const [ issues, setIssues ] = useState(fetchIssue);

  return (
    <Fragment>
      <Text>Display Issues!  {issues.summary}  {issues.description}</Text>
    </Fragment>
  );
};

export const run = render(
  <IssuePanel>
    <App />
  </IssuePanel>
);
1 Like

Resolved, i have to move

const { platformContext: { issueKey } } = useProductContext();

inside fetchIssue() function

2 Likes