How to use the easy-peasy.createContextStore 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-context-store.tsx View on Github external
/* eslint-disable */

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

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

interface InitialData {
  count: number;
}

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

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

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

interface InitialData {
  count: number;
}

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

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

function CountDisplay() {
  const count = Counter.useStoreState(state => state.count);
  const inc = Counter.useStoreActions(actions => actions.inc);
  return (
    <>
      <div>{count + 1}</div>
      <button type="button">
        +</button>
github pterodactyl / panel / resources / scripts / state / server / index.ts View on Github external
state.value = payload;
    }),
};

export interface ServerStore {
    server: ServerDataStore;
    subusers: ServerSubuserStore;
    databases: ServerDatabaseStore;
    files: ServerFileStore;
    schedules: ServerScheduleStore;
    socket: SocketStore;
    status: ServerStatusStore;
    clearServerState: Action;
}

export const ServerContext = createContextStore({
    server,
    socket,
    status,
    databases,
    files,
    subusers,
    schedules,
    clearServerState: action(state =&gt; {
        state.server.data = undefined;
        state.server.permissions = [];
        state.databases.data = [];
        state.subusers.data = [];
        state.files.directory = '/';
        state.files.selectedFiles = [];
        state.schedules.data = [];