Home  >  Article  >  Web Front-end  >  What is react redux?

What is react redux?

藏色散人
藏色散人Original
2019-04-29 15:58:235380browse

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.

What is react redux?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Things about WebSocketNext article:Things about WebSocket