No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

Installation

npm

npm i solid-gstatem

yarn

yarn add solid-gstatem

Live demo

Solid - Silent mode

Create a store

The exported functions can be used anywhere - in component, utils file, event listener, setTimeout, setInterval and promise callbacks.

Please use get and set functions with care as they won't trigger component re-render.

SolidStoreSilentMode
import * as solid from "solid-js";
import { create } from "solid-gstatem";

const initialState = { count: 0 };
const { useSelect, dispatch, get, set } = create(solid, {
  state: initialState
});

/* the count hook for function component */
export const useCount = () => useSelect(state => state.count);

/* This won't trigger component re-render */
export const getCount = () => get(state => state.count);

/* This won't trigger component re-render */
export const increaseCount = () => set(state => ({ count: state.count + 1 }));

/* increase the counter */
export const refreshCount = () =>
  dispatch({ count: getCount() }, { isForce: true });

Use the store in component

SolidSilentMode
import { useCount, increaseCount, refreshCount } from "./SolidStoreSilentMode";
import SolidCounter from "./SolidCounter";

const SolidSilentMode = () => {
  const count = useCount();
  return (
    <>
      <button onClick={refreshCount}>re-render</button>
      <SolidCounter value={count} onIncrement={increaseCount} />
    </>
  );
};

export default SolidSilentMode;