Getting Started With React Redux: Installation
Getting Started With React Redux: Installation
React Redux is the official React UI bindings layer for Redux. It lets your React
components read data from a Redux store, and dispatch actions to the store
to update state.
Installation
React Redux 8.x requires React 16.8.3 or later / React Native 0.59 or later, in
order to make use of React Hooks.
The recommended way to start new apps with React and Redux is by
using our official Redux+TS template for Vite, or by creating a new Next.js
project using Next's with-redux template.
https://github.com/rahsheen/react-native-template-redux-typescript
https://github.com/rahsheen/expo-template-redux-typescript
API Overview
Provider
React Redux includes a <Provider /> component, which makes the Redux store
available to the rest of your app:
import React from 'react'
import ReactDOM from 'react-dom/client'
// As of React 18
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
<Provider store={store}>
<App />
</Provider>
)
Hooks
React Redux provides a pair of custom React hooks that allow your React
components to interact with the Redux store.
useSelector reads a value from the store state and subscribes to updates,
while useDispatch returns the store's dispatch method to let you dispatch
actions.
import React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import {
decrement,
increment,
incrementByAmount,
incrementAsync,
selectCount,
} from './counterSlice'
import styles from './Counter.module.css'
Redux maintainer Mark Erikson appeared on the "Learn with Jason" show to
explain how we recommend using Redux today. The show includes a live-
coded example app that shows how to use Redux Toolkit and React-Redux
hooks with Typescript, as well as the new RTK Query data fetching APIs.
See the "Learn Modern Redux" show notes page for a transcript and links to
the example app source.
You can also ask questions on Stack Overflow using the #redux tag.
Docs Translati