Hello, I’m trying to use the Storage API to store the information described in my code, but I keep getting this error.
Trace ID: b76e84ef40caf33d
There was an error invoking the function - Cannot read property ‘useState’ of null
TypeError: Cannot read property ‘useState’ of null
at exports.useState (index.js:36002:423)
at Object.App [as type] (index.js:39704:94)
at index.js:33781:36
at asyncMap (index.js:33716:30)
at index.js:33737:35
at Object.exports.processAuxElement (index.js:33818:49)
at index.js:33262:49
at Reference.value (bootstrap.js:1:9280)
Here is my code.
import { storage } from '@forge/api';
import ForgeUI, { render, Text, GlobalSettings } from '@forge/ui';
import { useState, useEffect } from 'react';
const App = () => {
const [retrievedItems, setRetrievedItems] = useState('');
const createData = async () => {
const item = {
key: 'salut',
value: 'Bonjour',
};
await storage.set(item.key, item.value);
return [item];
};
const getData = async () => {
await createData();
const value = await storage.get('salut');
if (value) {
setRetrievedItems(value);
}
};
useEffect(() => {
getData();
}, []);
return <Text>{retrievedItems}</Text>;
};
export const run = render(
<GlobalSettings>
<App />
</GlobalSettings>
);
would you please help me ?
Thanks.