Storage API isn't working undefined set

Hi guys,

I have some trouble with storage API. I wanna store some values and I always get the same error and I have absolutely no clue what it might be. I share some of my code and I hope someone can help me out here.

manifest.yml

permissions:
  scopes:
    - read:jira-work
    - storage:app

**admin.jsx**
import { storage } from '@forge/api';
const Choose = () => {
  storage.set('key', [ 'Hello', 'World' ]);
  const [formState, setFormState] = useState(undefined);

  const onSubmit = async (formData) => {

    var languages = formData["products"];

    console.log(languages);

    setFormState(formData);

  };

That’s the error
Screenshot from 2021-05-27 21-55-42

Everything looks right in your code according to the docs.

The thing I was looking into was maybe something weird with Function hoisting. I’m assuming the storage.set call would work before the const Choose declaration?

Hey man, thanks for your fast response.
I tried that one out before and after your answer but the error stays. hm, is there a work around to save values?

I finally found out, why the API wasn’t working.
I checked my package.json. And there you are somehow the version of my API didn’t seem to be right.

changed them to newest version.

"dependencies": {
    "@forge/api": "^1.2.0",
    "@forge/ui": "^0.13.1"
1 Like