1.1.2 • Published 4 years ago

react-estate v1.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

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

propdefaulttypedescription
childrennullnodeRequired: React component
defaultState{}objectOptional: initial app state
reducerold,newvoidOptional: controled update

Example usage at: Multiplayer

1.1.1

4 years ago

1.1.2

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago