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
- Host: GitHub
- URL: https://github.com/graphql-editor/state
- Owner: graphql-editor
- Created: 2018-08-14T11:55:38.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-17T12:21:25.000Z (almost 8 years ago)
- Last Synced: 2025-02-21T15:51:38.670Z (over 1 year ago)
- Language: TypeScript
- Size: 22.5 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
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}}
);
```