Lightweight (<600B minified + gzipped) React Hook to subscribe to a subset of your single app state.
Lightweight (<600B minified + gzipped) React Hook to subscribe to a subset of your single app state.
Lightweight ([ { return { count: state.count }; });
return (
); }
## Features
- ⏬ Lightweight ([ {
return { count: state.count };
});
return (
);
}
ReactDOM.render(
,
rootElement
);Redux is a library used to create stores that can be updated via reducers. In fact, useSubstate works flawlessly with your current Redux store.
In opposite to react-redux, this library only requires a selectSubstate function (similar to react-redux's mapStateToProps). It is meant to call the dispatch function with the action directly. Advanced concepts like connectAdvanced or mapDispatchToProps are deliberately not supported.
To use useSubstate with your current react-redux React application, find the react-redux Provider and make sure to wrap it with a SubstateProvider:
import React from "react";
import { render } from "react-dom";
import { Provider } from "react-redux";
+ import { SubstateProvider } from "use-substate";
import { createStore } from "redux";
import todoApp from "./reducers";
import App from "./components/App";
const store = createStore(todoApp);
render(
+
+ ,
document.getElementById("root")
);Besides the open issue in react-redux, there are two other noticeable libraries that solve the a similiar problem:
Special thanks to @sophiebits and @gaearon for helping me spot an issue in my initial implementation and showing me how to fix it.
This library is also heavily influenced by the design of useReducer, create-subscription, react-redux, Reducer components in ReasonReact, Elm, Reagent (Clojure), Om (Clojure), and a lot of other libraries that I have seen over the years. Thank you all for pushing the Web forward ❤️.
Every help on this project is greatly appreciated. To get you started, here's a quick guide on how to make good and clean pull-requests:
Create a fork of this repository, so you can work on your own environment.
Install development dependencies locally:
git clone [email protected]:/use-substate.git
cd use-substate
yarn installMake changes using your favorite editor.
Commit your changes (here is a wonderful guide on how to make amazing git commits).
After a few seconds, a button to create a pull request should be visible inside the Pull requests section.
No open issues yet, or sync has not completed.