How to display or show result from storage in Forge

Please I need Urgent help. I save data to Storage as follows.

await storage.set('key1', {name: 'rahul', email: 'rahul@gmail.com' });
await storage.set('key1', {name: 'vasu', email: 'vasu@gmail.com' });

Here is my Issue.

Please how do I loop or map through the Stored data and render/displayed them within the Fragment components Eg. here

 <Fragment>
	
// Map the stored data here
      <Text>Display Records from storage</Text>
      
  </Fragment>

This is my coding so far. can someone help me with a working code please


import api, { route } from "@forge/api";
import ForgeUI, { render, Fragment, Text, IssuePanel, useProductContext, useState, Component} from "@forge/ui";
import { storage, fetch } from '@forge/api';

const App = () => {	 

await storage.set('key1', {name: 'rahul', email: 'rahul@gmail.com' });
await storage.set('key1', {name: 'vasu', email: 'vasu@gmail.com' });
const result = await storage.get('key1');
return result;
	   


  return (
    <Fragment>
	
// Map the stored data here
      <Text>Display Records from storage</Text>
      
  </Fragment>
  );
};

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

Thanks

You can query the storage.

const queryResults = await storage
  .query()
  .where('key', startsWith('key'))
  .getMany();

https://developer.atlassian.com/platform/forge/runtime-reference/storage-api-query/

Edited:
I think you are doing it wrong somehow. Here you are using the same key “key1” for two users. The forge storage will override the first user, means you save the user “rahul” first, then replace it with “vasu”.

await storage.set('key1', {name: 'rahul', email: 'rahul@gmail.com' });
await storage.set('key1', {name: 'vasu', email: 'vasu@gmail.com' });

I suggest that you build up the key based on the username, for example users#rahul, users#vasu, then you can query using .where('key', startsWith('users#'))

1 Like