All Projects → GitbookIO → unstated

GitbookIO / unstated

Licence: other
Simple state management for react

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to unstated

crypto-currency
A Flutter application showing crypto currency rates.
Stars: ✭ 16 (+33.33%)
Mutual labels:  state-management
ngx-mobx
Mobx decorators for Angular Applications
Stars: ✭ 14 (+16.67%)
Mutual labels:  state-management
hoox
Functional react state management base on hooks
Stars: ✭ 80 (+566.67%)
Mutual labels:  state-management
yurt
high quality mounted real (e)states
Stars: ✭ 53 (+341.67%)
Mutual labels:  state-management
atomic-state
Atomic State is a state management library for React
Stars: ✭ 15 (+25%)
Mutual labels:  state-management
asyncmachine
Relational State Machine with a visual inspector
Stars: ✭ 67 (+458.33%)
Mutual labels:  state-management
tuxi
✨ White glove service for your async needs
Stars: ✭ 14 (+16.67%)
Mutual labels:  state-management
flutter super state
A simple super state management library for Flutter (with async support)
Stars: ✭ 22 (+83.33%)
Mutual labels:  state-management
mst-effect
💫 Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (+58.33%)
Mutual labels:  state-management
XUI
XUI makes modular, testable architectures for SwiftUI apps a breeze!
Stars: ✭ 100 (+733.33%)
Mutual labels:  state-management
quick-redux
helper functions to make redux and react development quicker
Stars: ✭ 61 (+408.33%)
Mutual labels:  state-management
gstate
A crazy state management for lazy programmers
Stars: ✭ 27 (+125%)
Mutual labels:  state-management
NObservable
MobX like observable state management library with Blazor support
Stars: ✭ 66 (+450%)
Mutual labels:  state-management
reactive-states
Reactive state implementations (brainstorming)
Stars: ✭ 51 (+325%)
Mutual labels:  state-management
UniTEA
Implementation of The Elm Architecture for Unity3D
Stars: ✭ 31 (+158.33%)
Mutual labels:  state-management
bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 12 (+0%)
Mutual labels:  state-management
almy
🗄️ 673 bytes store for managing the state in your application
Stars: ✭ 26 (+116.67%)
Mutual labels:  state-management
query-param-store
Angular Reactive Query Parameters Store
Stars: ✭ 15 (+25%)
Mutual labels:  state-management
immutable-cursor
👊 Immutable cursors incorporating the Immutable.js interface over a Clojure-inspired atom
Stars: ✭ 58 (+383.33%)
Mutual labels:  state-management
nstate
A simple but powerful react state management library with low mind burden
Stars: ✭ 11 (-8.33%)
Mutual labels:  state-management

@gitbook/unstated

Simple state library for react application. It is based on unstated by James Kyle.

Installation

$ yarn add @gitbook/unstated

Usage

import { Container, useUnstated } from '@gitbook/unstated';

class Counter extends Container<{
    count: number
}> {
    state = {
        count: 0
    };

    increment() {
        this.setState({ count: this.state.count + 1 });
    }

    decrement() {
        this.setState({ count: this.state.count - 1 });
    }
}

function Counter() {
    const counter = useUnstated(Counter);

    return (
        <div>
            <button onClick={() => counter.decrement()}>-</button>
            <span>{counter.state.count}</span>
            <button onClick={() => counter.increment()}>+</button>
        </div>
    );
}

render(
    <Provider>
        <Counter />
    </Provider>,
    document.getElementById('root')
);

API

useUnstated

import { useUnstated } from '@gitbook/unstated';

useUnstated(
    C: ContainerConstructor,
    shouldUpdate?: (C: Container) => any
): Container

Hook to access a container and update the compontent each time the state is updated.

The shouldUpdate function can be used to prevent update of your component for certain updates of state. The result of the function will be shallowly compare to previous result.

useContainer

import { useContainer } from '@gitbook/unstated';

useContainer(
    C: ContainerConstructor
): Container

Similar to useUnstated but the component is not updated when the state is updated. You can use this hook to access actions to modify the container.

Credits

This module is based on unstated. It started as a fork to add support for hooks.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].