Trouble getting and setting values in forge storage

I’m trying to create a configuration page for my app that allows users to set a single property and then view the currently set value of that property. When running await storage.get(‘some-key’) the call is either silently failing or not returning anything. Here is my code so far, am I missing something?


export const WebhookInput = () => {
    const [formState, setFormState] = useState(undefined);
    const [currentWebhook, setCurrentWebhook] = useState(undefined)

    useEffect(() => {
      const getCurrentWebhook = async () => {
        console.log(`getting from storage`)
        const wh = await storage.get("webhook-url")
        console.log(`storage response is ${wh}`)
        setCurrentWebhook(wh)
      }
  
      getCurrentWebhook().catch(console.error);
    }, [])


    const onSubmit = async (formData) => {
      setFormState(formData);
      await storage.set("webhook-url", formData['webhook'])
    };

    return (
      <Fragment>
        <Form onSubmit={onSubmit}>
          <TextField name="webhook" label="Webhook Url" isRequired />
        </Form>
        {formState && <Text>{JSON.stringify(formState)}</Text>}
        <Text>Current Webhook URL: {JSON.stringify(currentWebhook)}</Text>
      </Fragment>
    );
  };

When running this with forge tunnel I get the following logs, but never make it to the storage response.

Listening for requests…

invocation: 0000000000000000884ee5b2cfcc3f80 index.runAdminPage
INFO 16:46:40.138 0000000000000000884ee5b2cfcc3f80 getting from storage

Hi Christian

Are you using the UI Kit? In that case this should help solve your problem.

I haven’t run the code but these changes should help.

    useEffect(async () => {
      const getCurrentWebhook = async () => {
        console.log(`getting from storage`)
        const wh = await storage.get("webhook-url")
        console.log(`storage response is ${wh}`)
        setCurrentWebhook(wh)
      }
  
      await getCurrentWebhook().catch(console.error);
    }, [])