How to use the react-hooks-global-state.createGlobalState function in react-hooks-global-state

To help you get started, we’ve selected a few react-hooks-global-state 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 dvaJi / ReaderFront / src / state.js View on Github external
preloadImages: 3, // 0 to 20
  qualityImage: 100
};

const initialState = {
  theme: getLSItem('theme') || 'light',
  language: 'es',
  displaySettings: displaySettingsLS || displaySettings,
  coreSettings: coreSettingsLS || coreSettings
};

const {
  GlobalStateProvider,
  setGlobalState,
  useGlobalState
} = createGlobalState(initialState);

export const setTheme = theme => {
  window.localStorage.setItem('theme', theme);
  setGlobalState('theme', theme);
};

export const setLanguage = language => {
  setGlobalState('language', language);
};

export const setDisplaySettings = displaySettings => {
  setLSItem('displaySettings', displaySettings);
  setGlobalState('displaySettings', displaySettings);
};

export const setCoreSettings = coreSettings => {
github dai-shi / react-hooks-global-state / examples / 01_minimal / src / index.js View on Github external
import React, { StrictMode } from 'react';
import ReactDOM from 'react-dom';

import { createGlobalState } from 'react-hooks-global-state';

const initialState = {
  count: 0,
  text: 'hello',
};
const { GlobalStateProvider, useGlobalState } = createGlobalState(initialState);

const Counter = () => {
  const [value, update] = useGlobalState('count');
  return (
    <div>
      <span>Count: {value}</span>
      <button type="button"> update(value + 1)}&gt;+1</button>
      <button type="button"> update(value - 1)}&gt;-1</button>
    </div>
  );
};

const TextBox = () =&gt; {
  const [value, update] = useGlobalState('text');
  return (
    <div></div>

react-hooks-global-state

Simple global state for React with Hooks API without Context API

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis