react-global-state-lib

1.0.1 • Public • Published

react-global-state-lib

package version package downloads standard-readme compliant package license make a pull request JavaScript Style Guide

Global state using Context & Hooks APIs

Table of Contents

Install

This project uses node and npm.

$ npm install react-global-state-lib
$ # OR
$ yarn add react-global-state-lib

Usage

import React, { Component } from 'react'

import initGlobalState from 'react-global-state-lib'


const {GlobalStateProvider, useGlobalState} = initGlobalState({
	count: 1, // initial state
})

function Counter() {
	const [global, setGlobalState] = useGlobalState()

	return <h1>{global.count}</h1>
}

function IncrementBtn() {
	const [global, setGlobalState] = useGlobalState()

	return (
		<button type="button" onClick={() => setGlobalState({count: global.count + 1})}>
			+
		</button>
	)
}

function App() {
	return (
		<GlobalStateProvider>
			<Counter />
			<Counter />
			<Counter />
			<IncrementBtn />
		</GlobalStateProvider>
	)
}

export default App

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT © tiaanduplessis

/react-global-state-lib/

    Package Sidebar

    Install

    npm i react-global-state-lib

    Weekly Downloads

    5

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    9.18 kB

    Total Files

    14

    Last publish

    Collaborators

    • tiaanduplessis