0.0.11 • Published 4 years ago

rewow v0.0.11

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

rewow

Declarative state management for React

Counter App using pure function to modify state

import React from 'react';
import {createStore, useStore} from 'rewow';
const store = createStore({count: 0});
// an action is pure function, just returns next state
const Increase = (payload, state) => ({...state, count: state.count + 1});
const App = () => {
  const {count, dispatch} = useStore(store, state => ({count: state.count}));
  return (
    <>
      <h1>{count}</h1>
      <button onClick={() => dispatch(Increase)}>Increase</button>
    </>
  );
};

Using declarative syntax instead of pure state mutating function

import {mutate, add} from 'rewow';
const Increase = () => mutate({count: add(1)});

Conditional state mutating

import {mutate, add, cond} from 'rewow';
const isEvent = value => value % 2 === 0;
const Increase = () => mutate({count: cond({if: isEvent, then: add(1)})});
0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago