Giter Club home page Giter Club logo

broadstate's Introduction


Easy state manager for state values from one component to the other with useState and React Hooks in < 1KB!



npm

NPM

⚡️Overview

Have you ever tried to move the value of a state from a child to the parent without using large state managment tools like Redux, Mobx e.t.c ?. Broadstate is an easy state manager for state values from one component to the other with useState and React Hooks in < 1KB!

🔧 Installation

You can easily install this package with yarn or npm:

$ yarn add broad-state

or

$ npm install --save broad-state

✨ Features

  • 😎 Easy to learn
  • 📦 ~388b (gzipped)
  • 🙅‍♂️ Zero dependencies
  • ✂️ Super-flexible API
  • ✅ Fully tested and reliable
  • ⚒ CommonJS, ESM & browser standalone support

📖 Usage

Some usage terms you need to be familar with – createObservable, useBroadState

  • createObservable, takes in the central state you need to be observed,
  • useBroadState, hooks that handle reading state and dispatching actions

Here is a simple example

export const counter = createObservable(0);
// Other Observable value goes here
import React from 'react';
import { createObservable, useBroadState } from 'broad-state';
import { counter } from './observable';

export default function App() {
  const [state, setState] = useBroadState(counter);
  return (
    <div className="App">
      <h2>Broad State Demo</h2>
      <h1>{state}</h1>
      <button onClick={() => setState(state + 1)}>+</button>
      <button onClick={() => setState(state - 1)} disabled={state === 0}>
        -
      </button>
    </div>
  );
}

🤔Thought Process

Broadstate is built on top of React Hooks. I first tried this concept in a project i was working on and seeing the re-usability and convenience, I decided to convert it to a standalone open-source library for others to benefit from the awesomeness of React Hooks.

🤝 License

MIT © codewonders.dev  ·  GitHub @adenekan41 / codewonders

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.