State Persistence
Apps can persist data across sessions using the State Service โ a key-value store scoped to the app.
App State (shared across all users)
import { useSetAppState, useGetAppState } from "@dynatrace-sdk/react-hooks";
// Write state
const { execute: saveState } = useSetAppState();
saveState({ key: "config", body: { value: JSON.stringify({ theme: "dark", refreshRate: 30 }) } });
// Read state
const { data } = useGetAppState({ key: "config" });
const config = data ? JSON.parse(data.value) : null;
User State (per-user, private)
import { useSetUserAppState, useGetUserAppState } from "@dynatrace-sdk/react-hooks";
const { execute: saveQuery } = useSetUserAppState();
saveQuery({ key: "lastQuery", body: { value: "fetch dt.entity.host | limit 10" } });
const { data: savedQuery } = useGetUserAppState({ key: "lastQuery" });
Storage Type Scope Best For
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
App State All users Shared config, cached results
User State Single user Personal preferences, last query
Document Service All users Complex data, shared configs
๐ก States persist across app updates. Add a version field to your state to make future migrations easier.
๐ Try it: Explore the Dynatrace Hub for app inspiration. Look at how built-in apps like "Ownership" and "Releases" combine DQL, Strato components, and intents. Open their source (if available) to learn advanced patterns.