Skip to main content

Overview

JavaScript vs. TypeScript API

This API reference uses TypeScript vocabulary and syntax to describe both JavaScript and TypeScript flavors of the library. Most stuff in this library works the same way both in JS and TS, beside static type-checks, of course. Non-trivial differences between JS and TS flavors of the library will be explained explicitly where needed.

Classes

  • GlobalState — An object that holds and manages the global state content.
  • SsrContext — Holds data persistent across multiple SSR (server-side rendering) iterations.

Components

Functions

  • newAsyncDataEnvelope — Creates a new plain JS object, satisfying the AsyncDataEnvelopeT type, and with reasonable initial values of its fields.
  • withGlobalStateType — Returns a set of library components, classes, and hooks "locked-in" onto a specified state type. Thus, making it unnecessary (in TypeScript) to pass the state type as a generic parameter for each component, class, and hook, when they are used, and allowing TypeScript compiler to auto-evaluate their other generic parameters in many cases.

Environment Variables

Hooks

  • getGlobalState() — Gets GlobalState instance from the context.
  • getSsrContext() — Gets SsrContext object (the server-side rendering context, which is used to pass global-state-related data between rendering iterations).
  • useAsyncCollection() — Resolves and stores at the given path of global state elements of an asynchronous data collection.
  • useAsyncData() — Resolves asynchronous data, and stores them at the given path of global state.
  • useGlobalState() — The primary hook for interacting with the global state, modeled after the standard React's useState().

TypeScript Types