Persist Global Settings of a confluence app using storage api


I m building an app with forge and I want to use the Global Settings. While I m able to persist the values using the storage api I m not able to retrieve them on page load.
Can you please help?

const onSubmit = async (formData) => {

	const options = {}
	options.headers = {
		"Authorization": formData['accessToken']
	const result = await fetch(formData['url'] + "/me", options)
	if (result.ok){
		await storage.set("url", formData['url'])
		await storage.set("accessToken", formData['accessToken'])
	} else {
		throw Error(result.status + " - " + result.statusText)

export const globalConfig = render(
			<Form onSubmit={onSubmit}>
				<TextField name={"url"} label={"URL"} defaultValue={???}/>
				<TextField name={"accessToken"} label={"accessToken"} defaultValue={???}/>

Hi @aalexandrakis ,

Take a look at the UI kit hooks documentation. You should be able to use useState to get the state. Here’s how the Forge getting started guide does it:

const [comments] = useState(async () => await fetchCommentsForContent(context.contentId));


1 Like

Hi @dmorrow and thanks for your reply,
unfortunately this didn’t work

const [url] = useState(async () => await storage.get("url"));
const [accessToken] = useState(async () => await storage.get("url"));

export const globalConfig = render(
			<Form onSubmit={onSubmit}>
				<TextField name={"url"} label={"URL"} defaultValue={url}/>
				<TextField name={"accessToken"} label={"Access Token"} defaultValue={accessToken}/>

I m getting compilation errors

Error: Error thrown in the snapshot context.
App code snapshot error: cannot use a hook outside of a component
Learn more about the snapshot context at

Should I use something else than storage api to persist global settings values ?