An open API service indexing awesome lists of open source software.

https://github.com/graphql-editor/state

State manager for typescript frontend & slothking
https://github.com/graphql-editor/state

Last synced: 12 months ago
JSON representation

State manager for typescript frontend & slothking

Awesome Lists containing this project

README

          

# State management for slothking frontend

Hello from [slothking.online](https://slothking.online)
Communicate with slothking backend without writing communication libs. Based on great lib [unstated](https://github.com/jamiebuilds/unstated)

## Installation

```sh
$ npm install @slothking-online/state
```

## Usage

```tsx
import { SlothContainer } from "@slothking-online/state";
import { Subscribe } from "unstated";
type MyState = {
someValue: string;
someOther: number[];
};

const appName = "superManager";
const myContainer = new SlothContainer(appName);

fetch("myApiFunction/").then(myContainer.set);

const MyReactComponent = () => (

{(con: typeof myContainer) =>

{con.state.someValue}
}

);
```

## Usage with slothking generated api

```tsx
import { SlothContainer } from "@slothking-online/state";
import { Subscribe } from "unstated";
import { userExtensionState } from './api';

const appName = "superManager";
const myContainer = new SlothContainer(appName);

api.user.endpoints.login(props:{username:'aaa',password:'ppp'}).then(myContainer.set)

const MyReactComponent = () => (

{(con: typeof myContainer) => { return con.state.valid ?

User logged in
:
User logged out
}}

);
```