All Projects → atlassian → React Sweet State

atlassian / React Sweet State

Licence: mit
Shared state management solution for React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Sweet State

Unstated Next
200 bytes to never think about React state management libraries ever again
Stars: ✭ 3,784 (+604.66%)
Mutual labels:  state-management
Mobius.swift
A functional reactive framework for managing state evolution and side-effects [Swift implementation]
Stars: ✭ 361 (-32.77%)
Mutual labels:  state-management
Vue Stash
Easily share reactive data between your Vue components.
Stars: ✭ 412 (-23.28%)
Mutual labels:  state-management
Grox
Grox helps to maintain the state of Java / Android apps.
Stars: ✭ 336 (-37.43%)
Mutual labels:  state-management
Ngrx Actions
⚡️ Actions and Reducer Utilities for NGRX
Stars: ✭ 348 (-35.2%)
Mutual labels:  state-management
States rebuilder
a simple yet powerful state management technique for Flutter
Stars: ✭ 372 (-30.73%)
Mutual labels:  state-management
Effector
The state manager ☄️
Stars: ✭ 3,572 (+565.18%)
Mutual labels:  state-management
Roxie
Lightweight Android library for building reactive apps.
Stars: ✭ 441 (-17.88%)
Mutual labels:  state-management
Pvm
Build workflows, activities, BPMN like processes, or state machines with PVM.
Stars: ✭ 348 (-35.2%)
Mutual labels:  state-management
React Recollect
State management for React
Stars: ✭ 411 (-23.46%)
Mutual labels:  state-management
Beedle
A tiny library inspired by Redux & Vuex to help you manage state in your JavaScript apps
Stars: ✭ 329 (-38.73%)
Mutual labels:  state-management
Provider
InheritedWidgets, but simple
Stars: ✭ 3,988 (+642.64%)
Mutual labels:  state-management
Westore
更好的小程序项目架构
Stars: ✭ 3,897 (+625.7%)
Mutual labels:  state-management
Blue Chip
Normalizes GraphQL and JSON:API payloads into your state management system and provides ORM selectors to prepare data to be consumed by components
Stars: ✭ 332 (-38.18%)
Mutual labels:  state-management
Jumpstate
Jumpstate is a simple and powerful state management utility for Redux.
Stars: ✭ 429 (-20.11%)
Mutual labels:  state-management
Constate
React Context + State
Stars: ✭ 3,519 (+555.31%)
Mutual labels:  state-management
Machinery
State machine thin layer for structs (+ GUI for Phoenix apps)
Stars: ✭ 367 (-31.66%)
Mutual labels:  state-management
React Hooks
Essential set of React Hooks for convenient Web API consumption and state management.
Stars: ✭ 515 (-4.1%)
Mutual labels:  state-management
Easy Peasy
Vegetarian friendly state for React
Stars: ✭ 4,525 (+742.64%)
Mutual labels:  state-management
Dutier
The immutable, async and hybrid state management solution for Javascript applications.
Stars: ✭ 401 (-25.33%)
Mutual labels:  state-management

react-sweet-state logo

react-sweet-state

The good parts of Redux and React Context in a flexible, scalable and easy to use state management solution

Philosophy

sweet-state is heavily inspired by Redux mixed with Context API concepts. It has render-prop components or hooks, connected to Store instances (defined as actions and initial state), receiving the Store state (or part of it) and the actions as a result.

Each Subscriber, or Hook, is responsible to get the instantiated Store (creating a new one with initialState if necessary), allowing sharing state across your project extremely easy.

Similar to Redux thunks, actions receive a set of arguments to get and mutate the state. The default setState implementation is similar to React setState, accepting an object that will be shallow merged with the current state. However, you are free to replace the built-in setState logic with a custom mutator implementation, like immer for instance.

Basic usage

npm i react-sweet-state
# or
yarn add react-sweet-state

Creating a Subscriber

import { createStore, createSubscriber, createHook } from 'react-sweet-state';

const Store = createStore({
  // value of the store on initialisation
  initialState: {
    count: 0,
  },
  // actions that trigger store mutation
  actions: {
    increment: () => ({ setState, getState }) => {
      // mutate state synchronously
      setState({
        count: getState().count + 1,
      });
    },
  },
  // optional, mostly used for easy debugging
  name: 'counter',
});

const CounterSubscriber = createSubscriber(Store);
// or
const useCounter = createHook(Store);
// app.js
import { useCounter } from './components/counter';

const CounterApp = () => {
  const [state, actions] = useCounter();
  return (
    <div>
      <h1>My counter</h1>
      {state.count}
      <button onClick={actions.increment}>+</button>
    </div>
  );
};

Documentation

Check the docs website or the docs folder.

Examples

See sweet-state in action: run npm run start and then go and check each folder:

  • Basic example with Flow typing http://localhost:8080/basic-flow/
  • Advanced async example with Flow typing http://localhost:8080/advanced-flow/
  • Advanced scoped example with Flow typing http://localhost:8080/advanced-scoped-flow/

Contributing

To test your changes you can run the examples (with npm run start). Also, make sure you run npm run preversion before creating you PR so you will double check that linting, types and tests are fine.

Thanks

This library merges ideas from redux, react-redux, redux-thunk, react-copy-write, unstated, bey, react-apollo just to name a few. Moreover it has been the result of months of discussions with ferborva, pksjce, TimeRaider, dpisani, JedWatson, and other devs at Atlassian.


With ❤️ from Atlassian

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].