Home > Article > Web Front-end > What is react redux?
React-Redux is the official React binding library for Redux. It enables your React components to read data from the Redux store and dispatch actions to the store to update the data.
Installation
Use React-Redux in your React app:
npm install --save react-redux
or
yarn add react-redux
In short In short, react-redux is a lightweight encapsulation library with only two core methods: Provider and connect.
React-Redux provides the 033de7db1b23dc23756a29338cfed1b2 component, which enables your entire app to access data in the Redux store:
import React from "react"; import ReactDOM from "react-dom"; import { Provider } from "react-redux"; import store from "./store"; import App from "./App"; const rootElement = document.getElementById("root"); ReactDOM.render( <Provider store={store}> <App /> </Provider>, rootElement );
React-Redux provides a connect method that allows you to Components and stores are connected.
Usually you can call the connect method in the following way:
import { connect } from "react-redux"; import { increment, decrement, reset } from "./actionCreators"; // const Counter = ... const mapStateToProps = (state /*, ownProps*/) => { return { counter: state.counter }; }; const mapDispatchToProps = { increment, decrement, reset }; export default connect( mapStateToProps, mapDispatchToProps )(Counter);
Related recommendations: "javascript tutorial"
The above is the detailed content of What is react redux?. For more information, please follow other related articles on the PHP Chinese website!