Access data from the server-side initial state API within apps https://npmjs.org/@nextcloud/initial-state
Перейти к файлу
dependabot[bot] 83778c15db
chore(deps-dev): Bump typescript from 5.5.4 to 5.6.2
---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-14 02:57:23 +00:00
.github Update dependabot-approve-merge.yml from org 2024-09-02 17:38:06 +02:00
LICENSES ci: Add reuse check 2024-07-08 16:18:10 +02:00
lib chore: Add SPDX header 2024-07-08 16:17:28 +02:00
test chore: Add SPDX header 2024-07-08 16:17:28 +02:00
.eslintrc.json
.gitignore chore: Add SPDX header 2024-07-08 16:17:28 +02:00
.npmignore chore: Add SPDX header 2024-07-08 16:17:28 +02:00
AUTHORS.md chore: Add SPDX header 2024-07-08 16:17:28 +02:00
CHANGELOG.md chore: Add SPDX header 2024-07-08 16:17:28 +02:00
LICENSE
README.md docs: Add reuse badge 2024-07-08 16:29:05 +02:00
REUSE.toml chore: Add SPDX header 2024-07-08 16:17:28 +02:00
package-lock.json chore(deps-dev): Bump typescript from 5.5.4 to 5.6.2 2024-09-14 02:57:23 +00:00
package.json chore(deps-dev): Bump typescript from 5.5.4 to 5.6.2 2024-09-14 02:57:23 +00:00
tsconfig.json
vite.config.ts chore: Add SPDX header 2024-07-08 16:17:28 +02:00
vitest.config.ts chore: Add SPDX header 2024-07-08 16:17:28 +02:00

README.md

@nextcloud/initial-state

REUSE status npm Test status Code coverage Documentation

Access data from the server-side initial state API within apps.

Installation

npm install @nextcloud/initial-state --save
yarn add @nextcloud/initial-state

Usage

Check "Providing the initial state with PHP" for more details about initial state.

Note: loadState throws an Error if the key isn't found, hence you might want to wrap the call with a try block.

import { loadState } from '@nextcloud/initial-state'

const val = loadState('myapp', 'user_preference')

// Provide a fallback value to return when the state is not found
const valWithFallback = loadState('myapp', 'user_preference', 'no_preference')

You can provide a type anotation for result.

import { loadState } from '@nextcloud/initial-state'

interface UserPreference {
  refreshInterval: number
}

const val = loadState<UserPreference>('myapp', 'user_preference', {
  refreshInterval: 15_000
})