Access data from the server-side initial state API within apps.
npm install @nextcloud/initial-state --saveyarn add @nextcloud/initial-stateCheck "Providing the initial state with PHP" for more details about initial state.
Note:
loadStatethrows anErrorif the key isn't found, hence you might want to wrap the call with atryblock.
import{loadState}from'@nextcloud/initial-state'constval=loadState('myapp','user_preference')// Provide a fallback value to return when the state is not foundconstvalWithFallback=loadState('myapp','user_preference','no_preference')You can provide a type anotation for result.
import{loadState}from'@nextcloud/initial-state'interfaceUserPreference{refreshInterval: number}constval=loadState<UserPreference>('myapp','user_preference',{refreshInterval: 15_000})