How to use storage

import ForgeUI, {
  render,
  Macro,
  MacroConfig,
  Text,
  TextField,
  useConfig
} from "@forge/ui";
import { storage, startsWith } from '@forge/api';
const defaultConfig = {
  name: "Unnamed Pet",
  age: "0"
};
const App = () => {
  (async function name(params) {
    console.log('123');
    await storage.set('survey-responses#1#{UUID}', { });
    await storage.set('survey-responses#1#{UUID}', { });
    await storage.set('survey-responses#1#{UUID}', { });
    await storage.set('survey-responses#1#{UUID}', { });
    const results = await storage
      .query()
      .where('key', startsWith('survey-response#1#'))
      .limit(10)
      .getMany();
      console.log(results);
  })();
  console.log(useConfig());
  // Retrieve the configuration
  const config = useConfig() || defaultConfig;
  // Use the configuration values
  return <Text>{config.name} is {config.age} years old.</Text>;
};
export const run = render(
  <Macro app={<App />} />
);
// Function that defines the configuration UI
const Config = () => {
  return (
    <MacroConfig>
      <TextField name="name" label="Pet name" defaultValue={defaultConfig.name} />
      <TextField name="age" label="Pet age" defaultValue={defaultConfig.age} />
    </MacroConfig>
  );
};
export const config = render(<Config />);

i use it but never used ,
function has been used but storage never use
who can give me a tutorial of some ideas thank you~

Hi @111112 ,

Maybe the thing you’re missing is useAction and useState hooks. Here’s some abbreviated code:

import ForgeUi, { useAction, useState, ...} from '@forge/ui';
const App = () => {
  const [initialData] = useAction(value => value, async () => await storage.query().where(etc).getMany());
  const [myData, setMyData] = useState(initialData);
  // From here on your app can reference myData and call setMyData. Depending on your app's
  // design, it may want to callSetMyData after calling storage.set().
}

Also see the UI kit hooks documentation.

Regards,
Dugald

2 Likes

my Technology stack is vue it’s my first time to use React
as a white
thank you~

1 Like