Understand React Redux from scrach on one page

Redux a popular React and React Native state management library.
Here is all component of redux in one page

npx create-react-app reactapp

cd reactapp

yarn add react-redux

Add this in index.js

import React from “react”;
import React…


This content originally appeared on DEV Community and was authored by Serge Jabo Byusa

Redux a popular React and React Native state management library.
Here is all component of redux in one page

npx create-react-app reactapp

cd reactapp

yarn add react-redux

Add this in index.js

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { createStore } from "redux";
import allReducer from "./reducers";

//ACTION  -> INCREMENT (describes what you want to do!) it's a simple function

const increment = () => {
    return {
        type: "INCREMENT",
    };
};

const decrement = () => {
    return {
        type: "DECREMENT",
    };
};

//REDUCER -> (action transfer from one state to another state, it gonna modify our store)
//You can have many reducers (Auth reducer, Movielist reducer etc ...)
const counter = (state = 0, action) => {
    switch (action.type) {
        case "INCREMENT":
            return state + 1;
        case "DECREMENT":
            return state - 1;
    }
};

//STORE  -> Globalized STATE
let store = createStore(counter);

//Display it in the console.
store.subscribe(() => console.log(store.getState()));

//DISPATCH (DISPATTCH this action to the reducer)
store.dispatch(increment());
store.dispatch(decrement());
store.dispatch(increment());

ReactDOM.render(
    <React.StrictMode>
        <App />
    </React.StrictMode>,
    document.getElementById("root")
);

reportWebVitals();

Testing it: check the console in inspect to see how it increments and decrements.

Check this repo for more advanced way of doing it:

https://github.com/Byusa/learn-redux

This repo shows the use of redux it could be one a proper way with the store and multiple reducers their own folders.

Reference:
https://www.youtube.com/watch?v=CVpUuw9XSjY


This content originally appeared on DEV Community and was authored by Serge Jabo Byusa


Print Share Comment Cite Upload Translate Updates
APA

Serge Jabo Byusa | Sciencx (2021-11-25T21:21:16+00:00) Understand React Redux from scrach on one page. Retrieved from https://www.scien.cx/2021/11/25/understand-react-redux-from-scrach-on-one-page/

MLA
" » Understand React Redux from scrach on one page." Serge Jabo Byusa | Sciencx - Thursday November 25, 2021, https://www.scien.cx/2021/11/25/understand-react-redux-from-scrach-on-one-page/
HARVARD
Serge Jabo Byusa | Sciencx Thursday November 25, 2021 » Understand React Redux from scrach on one page., viewed ,<https://www.scien.cx/2021/11/25/understand-react-redux-from-scrach-on-one-page/>
VANCOUVER
Serge Jabo Byusa | Sciencx - » Understand React Redux from scrach on one page. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/25/understand-react-redux-from-scrach-on-one-page/
CHICAGO
" » Understand React Redux from scrach on one page." Serge Jabo Byusa | Sciencx - Accessed . https://www.scien.cx/2021/11/25/understand-react-redux-from-scrach-on-one-page/
IEEE
" » Understand React Redux from scrach on one page." Serge Jabo Byusa | Sciencx [Online]. Available: https://www.scien.cx/2021/11/25/understand-react-redux-from-scrach-on-one-page/. [Accessed: ]
rf:citation
» Understand React Redux from scrach on one page | Serge Jabo Byusa | Sciencx | https://www.scien.cx/2021/11/25/understand-react-redux-from-scrach-on-one-page/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.