react-estate
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

react-estate

simple universal react state, the easiest way to setup global app state.

Getting Started

  1. yarn add react-estate or npm install react-estate

Usage

Add state provider at your initial entry point of your application usually index.js.

import { StateProvider } from "react-estate";
 
<StateProvider defaultState={state}>
  <App />
</StateProvider>;

use state across your application - example.

import React, { useEffect } from "react";
import { useStateValue } from "react-estate";
 
function App() {
  const [state, setState] = useStateValue();
 
  useEffect(() => {
    setState({ mounted: true });
    console.log("log state", state);
  }, []);
 
  // render your component like normal
  return null;
}

read state on a different component to access the shared state.

import React from "react";
import { useStateValue } from "react-estate";
 
function SomeView() {
  const [{ mounted }] = useStateValue();
  console.log("reading top level app state", mounted);
 
  // render your component like normal
  return null;
}

Available Props for StateProvider

prop default type description
children null node Required: React component
defaultState {} object Optional: initial app state
reducer old,new void Optional: controled update

Example usage at: Multiplayer

Package Sidebar

Install

npm i react-estate

Weekly Downloads

2

Version

1.1.2

License

MIT

Unpacked Size

6.92 kB

Total Files

8

Last publish

Collaborators

  • jeffmendez