# @nextcloud/initial-state

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

Latest version **3.0.0** (published 2025-08-01) · GPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @nextcloud/initial-state
pnpm add @nextcloud/initial-state
yarn add @nextcloud/initial-state
bun add @nextcloud/initial-state
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2025-08-01 |
| First published | 2019-10-02 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^20.0.0 \|\| ^22.0.0 \|\| ^24.0.0 |
| Dependencies | 0 |
| Unpacked size | 42.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Nextcloud GmbH and Nextcloud contributors |
| Maintainers | icewind1991, skjnldsv, pytal, christophwurst, juliushaertl, nickvergessen, artonge, marcoambrosinii, st3iny, gretadoci, max-nextcloud, mejo-, susnux |
| Keywords | nextcloud |

## Links

- npm: https://www.npmjs.com/package/@nextcloud/initial-state
- Repository: https://github.com/nextcloud-libraries/nextcloud-initial-state
- Homepage: https://github.com/nextcloud-libraries/nextcloud-initial-state#readme
- Issues: https://github.com/nextcloud-libraries/nextcloud-initial-state/issues
- npm.io page: https://npm.io/package/@nextcloud/initial-state

## Recent versions

- 3.0.0 (latest) — 2025-08-01
- 2.2.0 — 2024-04-29
- 2.1.0 — 2023-07-11
- 2.0.0 — 2022-08-24
- 1.2.1 — 2021-11-02
- 1.2.0 — 2020-10-09
- 1.1.2 — 2020-04-06
- 1.1.1 — 2020-03-19
- 1.1.0 — 2020-01-08
- 1.0.0 — 2019-12-18
- 0.2.0 — 2019-10-03
- 0.1.0 — 2019-10-02

## README

<!--
  - SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  - SPDX-License-Identifier: GPL-3.0-or-later
-->	
# @nextcloud/initial-state
[![REUSE status](https://api.reuse.software/badge/github.com/nextcloud-libraries/nextcloud-initial-state)](https://api.reuse.software/info/github.com/nextcloud-libraries/nextcloud-initial-state)
[![npm](https://img.shields.io/npm/v/@nextcloud/initial-state.svg)](https://www.npmjs.com/package/@nextcloud/initial-state)
[![Test status](https://img.shields.io/github/actions/workflow/status/nextcloud-libraries/nextcloud-initial-state/node-test.yml?label=tests)](https://github.com/nextcloud-libraries/nextcloud-initial-state/actions/workflows/node-test.yml?query=branch%3Amaster)
[![Code coverage](https://img.shields.io/codecov/c/gh/nextcloud-libraries/nextcloud-initial-state/master)](https://app.codecov.io/gh/nextcloud-libraries/nextcloud-initial-state)
[![Documentation](https://img.shields.io/badge/Documentation-online-brightgreen)](https://nextcloud.github.io/nextcloud-initial-state/)

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

## Installation

```sh
npm install @nextcloud/initial-state --save
```

```sh
yarn add @nextcloud/initial-state
```

## Usage

> Check ["Providing the initial state with PHP"](https://docs.nextcloud.com/server/latest/developer_manual/basics/front-end/js.html#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.

```js
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.

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

interface UserPreference {
  refreshInterval: number
}

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

---
_Source: https://npm.io/package/@nextcloud/initial-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
