All Projects → hlhr202 → React-Combine-Provider

hlhr202 / React-Combine-Provider

Licence: MIT License
combine react providers in ease

Programming Languages

typescript
32286 projects
HTML
75241 projects

Projects that are alternatives of or similar to React-Combine-Provider

Constate
React Context + State
Stars: ✭ 3,519 (+12034.48%)
Mutual labels:  hooks, react-state, react-context, constate, react-hooks
useAudioPlayer
Custom React hook & context for controlling browser audio
Stars: ✭ 176 (+506.9%)
Mutual labels:  hooks, react-hooks
tacklebox
🎣React UX components for handling common interactions
Stars: ✭ 15 (-48.28%)
Mutual labels:  hooks, react-hooks
max-todos
A basic Todo app developed in React.
Stars: ✭ 19 (-34.48%)
Mutual labels:  hooks, react-hooks
react-captain
⚓ A collection of strongly typed React hooks and contexts.
Stars: ✭ 15 (-48.28%)
Mutual labels:  react-context, react-hooks
jedisdb
redis like key-value state management solution for React
Stars: ✭ 13 (-55.17%)
Mutual labels:  hooks, react-hooks
use-window-focus
React Hook to check if window is focused
Stars: ✭ 19 (-34.48%)
Mutual labels:  hooks, react-hooks
react-cool-form
😎 📋 React hooks for forms state and validation, less code more performant.
Stars: ✭ 246 (+748.28%)
Mutual labels:  hooks, react-hooks
react-daterange-picker
A react date range picker to using @material-ui. Live Demo: https://flippingbitss.github.io/react-daterange-picker/
Stars: ✭ 85 (+193.1%)
Mutual labels:  hooks, react-hooks
react-abac
Attribute Based Access Control for React
Stars: ✭ 54 (+86.21%)
Mutual labels:  react-context, react-hooks
react-europe-2019
Slides and demo app from my keynote
Stars: ✭ 29 (+0%)
Mutual labels:  hooks, react-hooks
use-query-string
🆙 A React hook that serializes state into the URL query string
Stars: ✭ 50 (+72.41%)
Mutual labels:  hooks, react-hooks
use-app-state
🌏 useAppState() hook. that global version of setState() built on Context.
Stars: ✭ 65 (+124.14%)
Mutual labels:  hooks, react-hooks
use-detect-print
A react hook to detect when a page is being printed
Stars: ✭ 55 (+89.66%)
Mutual labels:  hooks, react-hooks
resynced
An experimental hook that lets you have multiple components using multiple synced states using no context provider
Stars: ✭ 19 (-34.48%)
Mutual labels:  hooks, react-hooks
use-metamask
a custom React Hook to manage Metamask in Ethereum ĐApp projects
Stars: ✭ 131 (+351.72%)
Mutual labels:  hooks, react-hooks
react-emotion-multi-step-form
React multi-step form library with Emotion styling
Stars: ✭ 25 (-13.79%)
Mutual labels:  react-context, react-hooks
react-breakpoints
Respond to changes in a DOM element's size. With React Breakpoints, element queries are no longer "web design's unicorn" 🦄
Stars: ✭ 74 (+155.17%)
Mutual labels:  hooks, react-hooks
flhooks
React like Hooks implementation for Flutter.
Stars: ✭ 38 (+31.03%)
Mutual labels:  hooks, react-hooks
reason-hooks-lib
A set of reusable ReasonReact hooks.
Stars: ✭ 31 (+6.9%)
Mutual labels:  hooks, react-hooks

React Combine Provider

npm Coverage Status CircleCI TypeDefine License

Combine react providers in ease
Requires React >= 16.8.0
Fully support unstated-next and constate

Install

npm install --save react-combine-provider

Usage

  • unstated
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import { createContainer } from 'unstated-next';
import { combineProviders } from 'react-combine-provider';

const useCounter1 = (initialState = 1) => {
    const [count, setCount] = useState(initialState);
    const decrement = () => setCount(count - 1);
    const increment = () => setCount(count + 1);
    return { count, decrement, increment };
};

const Counter1 = createContainer(useCounter1);

const useCounter2 = (initialState = 2) => {
  const [count, setCount] = useState(initialState);
  const decrement = () => setCount(count - 2);
  const increment = () => setCount(count + 2);
  return { count, decrement, increment };
};

const Counter2 = createContainer(useCounter2);

function CounterDisplay1() {
  const counter1 = Counter1.useContainer();
  console.log('rendering');
  return (
    <div>
      <div>counter display 1</div>
      <div>counter 1</div>
      <button onClick={counter1.decrement}>-</button>
      <span>{counter1.count}</span>
      <button onClick={counter1.increment}>+</button>
      <br />
    </div>
  );
}

function CounterDisplay2() {
  const counter1 = Counter1.useContainer();
  const counter2 = Counter2.useContainer();
  return (
    <div>
      <div>counter display 2</div>
      <div>counter 1</div>
      <button onClick={counter1.decrement}>-</button>
      <span>{counter1.count}</span>
      <button onClick={counter1.increment}>+</button>
      <div>counter 2</div>
      <button onClick={counter2.decrement}>-</button>
      <span>{counter2.count}</span>
      <button onClick={counter2.increment}>+</button>
      <br />
    </div>
  );
}

const StateProviders = combineProviders([
  [Counter1.Provider, { initialState: 5 }],
  Counter2.Provider,
]);

function App() {
  return (
    <StateProviders>
      <CounterDisplay1 />
      <br />
      <CounterDisplay2 />
    </StateProviders>
  );
}

ReactDOM.render(<App />, document.getElementById('root'));

TODO

  • [] reference of hooks in another hooks
  • [] dynamic hooks injection
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].