How to use the easy-peasy.createComponentStore function in easy-peasy

To help you get started, we’ve selected a few easy-peasy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ctrlplusb / easy-peasy / src / __tests__ / typescript / create-component-store.tsx View on Github external
/* eslint-disable */

import * as React from 'react';
import { createComponentStore, Action, action } from 'easy-peasy';

interface StoreModel {
  count: number;
  inc: Action;
}

interface InitialData {
  count: number;
}

const useCounter = createComponentStore({
  count: 0,
  inc: action(state => {
    state.count += 1;
  }),
});

const useCounterWithInitializer = createComponentStore(
  data => ({
    count: data ? data.count + 1 : 0,
    inc: action(state => {
      state.count += 1;
    }),
  }),
);

function CountDisplay() {
github ctrlplusb / easy-peasy / src / __tests__ / typescript / create-component-store.tsx View on Github external
count: number;
  inc: Action;
}

interface InitialData {
  count: number;
}

const useCounter = createComponentStore({
  count: 0,
  inc: action(state => {
    state.count += 1;
  }),
});

const useCounterWithInitializer = createComponentStore(
  data => ({
    count: data ? data.count + 1 : 0,
    inc: action(state => {
      state.count += 1;
    }),
  }),
);

function CountDisplay() {
  const [state, actions] = useCounter();
  return (
    <>
      <div>{state.count + 1}</div>
      <button type="button">
        +
      </button>