@nextcloud/initial-state
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

@nextcloud/initial-state

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
})

/@nextcloud/initial-state/

    Package Sidebar

    Install

    npm i @nextcloud/initial-state

    Weekly Downloads

    9,554

    Version

    2.2.0

    License

    GPL-3.0-or-later

    Unpacked Size

    43.3 kB

    Total Files

    10

    Last publish

    Collaborators

    • susnux
    • pytal
    • gretadoci
    • mejo-
    • artonge
    • max-nextcloud
    • st3iny
    • marcoambrosinii
    • icewind1991
    • skjnldsv
    • christophwurst
    • juliushaertl
    • nickvergessen