1.0.6 • Published 6 years ago
rxjs-react-state-container v1.0.6
State container for React.js applications
Installation
npm:
npm i rxjs-react-state-containeryarn:
yarn add rxjs-react-state-containerUsage
- Import
Providerand wrap your main React Component with it. You can pass initialState to thestoreprop.
import { Provider } from "rxjs-react-state-container";
const initialState = {
todo: [],
about: {
full_name: "Hubert Jaruzal",
github: "https://github.com/hubertjaruzal",
}
}
ReactDOM.render(
<Provider store={initialState}>
<App/>
</Provider>,
document.getElementById("root"),
);- Import
connectif you want to use values from the global state inside your React Component.
import { connect } from "rxjs-react-state-container";
const About = (props) => (
<section>
<span>Created by: <a href={props.about.github} target="_blank" rel="noopener noreferrer">{props.about.full_name}</a></span>
</section>
)
export default connect()(About);- If you want to get only specific values from your global state, pass array with key values you are interested in.
export default connect(["about"])(About);- All Components, which are wrapped with
connectfunction, have possibility to update state. For that, useupdateStatefunction.
this.props.updateState({todo: ["clean my room", "be awesome"]});