{"id":101844,"date":"2020-02-12T16:00:36","date_gmt":"2020-02-12T14:00:36","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=101844"},"modified":"2020-02-11T19:37:49","modified_gmt":"2020-02-11T17:37:49","slug":"reactjs-and-redux-tutorial","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html","title":{"rendered":"ReactJS and Redux Tutorial"},"content":{"rendered":"<p>In this post, we look at using the Redux library with ReactJS. Redux, in a gist, centralizes state management. It provides APIs and patterns to manipulate the state in a predictable way. This leads to consistent application behavior. Wherein for the same set of changes we get the same resultant state every time, the change is predictable. <\/p>\n<p>As we work through this article we build a simple ReactJS application to take a ride through the Redux world. It seems intimidating at first but by the time we are done, you will have a better understanding of its benefits and an appreciation of the motivation behind it. Let us get started with some basic concepts first.<\/p>\n<h2 class=\"wp-block-heading\">1. Basic Concepts<\/h2>\n<p>Before we begin creating our sample application, let us go over some terms and their definitions first. Some of the key players in the Redux Universe are as follows:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Actions<\/em><\/span><\/p>\n<p>You can think of actions as JavaScript Object representing actions that trigger a change in the state of the application. We call or rather dispatch actions in response to an event that may or may not be the result of user action. The only rule with action objects is that they have a &#8220;type&#8221; property. Other than that the structure of the action object is up to us.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Reducers<\/em><\/span><\/p>\n<p>Reducers are JavaScript functions that actually change state in response to actions. These are basically pure functions, in that they do not change the data passed into them, rather they use it to create a new state.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Store<\/em><\/span><\/p>\n<p> This is a plain JavaScript object which holds the state of the entire application. Changes to the data stored in this object results in the re-rendering of the view. Remember its data is changed by reducers which in turn act when actions are triggered by our code. <\/p>\n<h2 class=\"wp-block-heading\">2. Basic Application Structure<\/h2>\n<p>Let us create a basic application structure and pull down all the npm packages we will need. To start off we use the create-react-app package to generate a basic ReactJS application like below:<\/p>\n<pre class=\"brush: bash;\">&gt;npx create-react-app my-app .<\/pre>\n<p>This generates a skeletal ReactJS app named my-app in the current folder.<\/p>\n<p>Next, since we will be working with Redux we install a few dependencies related to it among others.<\/p>\n<pre class=\"brush: bash;\">&gt; npm install redux react-redux prop-types redux-immutable-state-invariant\n\n<\/pre>\n<p>Now we are ready to build our ReactJS Redux application.<\/p>\n<h2 class=\"wp-block-heading\">3. ReactJS and Redux &#8211; Sample Application<\/h2>\n<p>We build a simple application that shows matching country names as the user types in a text box. The country names are fetched from a server API and populated in an unordered list below the text box. Our state will store the text typed in by the user and a list of matching country names fetched from the API. The shape of our state looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>initialState.js<\/em><\/span><\/p>\n<pre class=\"brush:js;\">export default {\n    user: {\n        text: \"\"\n    },\n    country: {\n        countries: [],\n        isLoading: false,\n        error: null\n    }\n};\n<\/pre>\n<h3 class=\"wp-block-heading\">3.1 Server API Setup<\/h3>\n<p>We use Nodejs and Express to quickly set up a server-side API. The API returns a list of countries matching the text supplied to it. The code for our server-side API looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>index.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">const express = require('express');\nconst app = express();\nconst bodyParser = require(\"body-parser\");\nconst api = require('.\/countryController');\nconst cors = require('cors');\n\napp.use(bodyParser.json());\napp.use(bodyParser.urlencoded({ extended: true }));\napp.use(cors());\napp.use('\/api', api());\n\nconst Port = process.env.PORT || 2019;\n\napp.listen(Port, () =&gt; {\n    console.log(`Listening on ${Port}.`);\n});\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>countryController.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">const router = require('express').Router();\n\nmodule.exports = () =&gt; {\n    router.get('\/country\/:code?', (req, res) =&gt; {\n        let code = req.params.code || \"\";\n        if (code) {\n            return res.json(countries.filter(c =&gt; c.code.toLowerCase().indexOf(code.toLowerCase()) &gt; -1 ||\n                c.name.toLowerCase().indexOf(code.toLowerCase()) &gt; -1));\n\n        }\n        return res.json(countries);\n    });\n    return router;\n};\n\nconst countries = [\n    { name: 'Afghanistan', code: 'AF' },\n    { name: '\u00c5land Islands', code: 'AX' },\n    { name: 'Albania', code: 'AL' },\n    { name: 'Algeria', code: 'DZ' },\n    { name: 'American Samoa', code: 'AS' },\n    { name: 'AndorrA', code: 'AD' },\n    { name: 'Angola', code: 'AO' },\n...\n<\/pre>\n<h3 class=\"wp-block-heading\">3.2 Setting up Redux<\/h3>\n<p>Redux does require a bit of verbose boilerplate code to get up and running. But don&#8217;t let this discourage you. Once you understand what each piece does it will not seem too daunting afterward.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>First let us set up our actions, remember, these are JavaScript objects with a mandatory type property. We will create three files for this, namely, actionTypes.js, countryActions.js, and userActions.js. actionTypes.js stores string constants with names of our actions. The other two files contain what are called action creators. Action creators are basically JavaScript functions that return action objects. <\/p>\n<p><span style=\"text-decoration: underline\"><em>actionTypes.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">export const FETCH_COUNTRIES_BEGIN = \"FETCH_COUNTRIES_BEGIN\";\nexport const FETCH_COUNTRIES_SUCCESS = \"FETCH_COUNTRIES_SUCCESS\";\nexport const FETCH_COUNTRIES_FAILED = \"FETCH_COUNTRIES_FAILED\";\nexport const USER_TEXT = \"USER_TEXT\";\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>countryActions.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import { FETCH_COUNTRIES_BEGIN, \n         FETCH_COUNTRIES_FAILED, \n         FETCH_COUNTRIES_SUCCESS } from '.\/actionTypes';\n\nexport function fetch_countries(result) {\n    return function (dispatch) {\n        dispatch(fetch_countries_begin(result))\n\n        return window.fetch(`http:\/\/localhost:2019\/api\/country\/${result}`)\n            .then(response =&gt;\n                response.json(),\n                (error) =&gt; {\n                    dispatch(fetch_countries_error(error));\n                }\n            ).then((res) =&gt; dispatch(fetch_countries_success(res)));\n    }\n}\n\nexport function fetch_countries_success(result) {\n    return { type: FETCH_COUNTRIES_SUCCESS, result };\n}\n\nexport function fetch_countries_error(result) {\n    return { type: FETCH_COUNTRIES_FAILED, result };\n}\n\nexport function fetch_countries_begin(result) {\n    return { type: FETCH_COUNTRIES_BEGIN, result };\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>userActions.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import { USER_TEXT } from '.\/actionTypes';\n\nexport function user_text(result) {\n    return { type: USER_TEXT, result };\n}\n<\/pre>\n<p>Now that our actions are setup let us set up our reducers next. Reducers are pure functions that take the previous state and action object as parameters and return a new state object. Simple enough, we create two separate reducers, one each to handle the user input and the list of countries from the API. But there is catch here since a reducer synchronously returns a state object how do we handle API calls or rather async operations.<\/p>\n<p>The standard way to do this is by using Redux-thunk. This store enhancing middleware allows reducers to return functions or promises. We will enhance our store later with the thunk middleware, but for now, we will assume it to be. Our reducers look like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>countryReducer.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import * as type from \"..\/actions\/actionTypes\";\nimport initialState from \".\/initialState\";\n\nexport default function country(state = initialState.country, action) {\n    switch (action.type) {\n        case type.FETCH_COUNTRIES_SUCCESS:\n            return { ...state, countries: action.result, isLoading: false, error: null };\n        case type.FETCH_COUNTRIES_FAILED:\n            return { ...state, countries: [], isLoading: false, error: action.result };\n        case type.FETCH_COUNTRIES_BEGIN:\n            return { ...state, countries: [], isLoading: true, error: null };\n        default:\n            return state;\n    }\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>userTextReducer.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import * as type from \"..\/actions\/actionTypes\";\nimport initialState from \".\/initialState\";\n\nexport default function user(state = initialState.user, action) {\n    switch (action.type) {\n        case type.USER_TEXT:\n            return { ...state, text: action.result };\n        default:\n            return state;\n    }\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>index.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import { combineReducers } from \"redux\";\nimport country from '.\/countryReducer';\nimport user from '.\/userReducer';\n\nconst rootReducer = combineReducers({\n    country,\n    user\n});\nexport default rootReducer;\n<\/pre>\n<p>Finally, it is time to set up our store. In Redux there is just one central store that stores all of our application&#8217;s state. The code looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>configureStore.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import { createStore, applyMiddleware, compose } from \"redux\";\nimport rootReducer from \".\/reducers\";\nimport reduxImmutableStateInvariant \n       from \"redux-immutable-state-invariant\";\nimport thunkMiddleware from \"redux-thunk\";\n\nexport default function configureStore(initialState) {\n    const composeEnhancers =\n        window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; \n        \/\/ add support for Redux dev tools\n\n    return createStore(\n        rootReducer,\n        initialState,\n        composeEnhancers(applyMiddleware(reduxImmutableStateInvariant(), thunkMiddleware))\n    );\n}\n<\/pre>\n<p>Now that we are done setting up Redux, let us move forward and work on our UI.<\/p>\n<h2 class=\"wp-block-heading\">4. Building UI Components<\/h2>\n<p>First, we will build our presentational components, viz., Input &amp; CountryList. The Input component renders a simple input tag for the user to type country names into. The code for this component looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Input.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React from 'react';\n\nexport default function Input(props) {\n    const handleChange = (event) =&gt; {\n        props.user_text(event.target.value);\n        props.fetch_countries(event.target.value);\n    }\n    return &lt;input type=\"text\" \n        style={{ margin: \"15px\", width: \"225px\" }}\n        placeholder=\"Type Country Name or Code\" \n        onChange={handleChange}\n        value={props.text} \/&gt;;\n}\n<\/pre>\n<p>Next, we build a component to show the list of countries from the API. Nothing fancy here just rendering an unordered list of country names. The code for this component looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>CountryList.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React from 'react';\n\nfunction CountryList(props) {\n    return &lt;&gt;\n        &lt;ul&gt;{\n            props.countries &amp;&amp; props.countries.map(c =&gt;\n                &lt;li key={c.code}&gt;{c.name}&lt;\/li&gt;\n            )}\n        &lt;\/ul&gt;\n    &lt;\/&gt;;\n}\nexport default CountryList;\n<\/pre>\n<p>Now let us build our Container Component to present the UI to the user. We call it HomePage.js, an important piece here is connecting this component to Redux using the connect method. It takes two arguments matchStateToProps and matchDispatchToProps. What the two do is to wire up the state of the application to props and actions to props. We then pass these down to presentational components to complete the example. The code for this HomePage component looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>HomePage.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React from 'react';\nimport Input from '..\/Common\/Input';\nimport CountryList from '..\/Common\/CountryList';\nimport * as countryActions from '..\/..\/Redux\/actions\/countryActions';\nimport * as userActions from '..\/..\/Redux\/actions\/userActions';\nimport { connect } from 'react-redux';\nimport { bindActionCreators } from \"redux\";\n\nfunction HomePage(props) {\n    return &lt;&gt;&lt;Input \n        user_text={props.actions.user_text}\n        fetch_countries={props.actions.fetch_countries}&gt;\n           &lt;\/Input&gt;\n           &lt;CountryList \n        countries={props.country.countries}&gt;\n           &lt;\/CountryList&gt;\n           &lt;\/&gt;;\n}\nconst matchStateToProps = (state) =&gt; {\n    return {\n        country: state.country,\n        text: state.text\n    }\n}\nconst matchDispatchToProps = (dispatch) =&gt; {\n    return {\n        actions: {\n            fetch_countries: bindActionCreators(countryActions.fetch_countries, dispatch),\n            fetch_countries_begin: \nbindActionCreators(countryActions.fetch_countries_begin, dispatch),\n            fetch_countries_success: \nbindActionCreators(countryActions.fetch_countries_success, dispatch),\n            fetch_countries_error: \nbindActionCreators(countryActions.fetch_countries_error, dispatch),\n            user_text: \nbindActionCreators(userActions.user_text, dispatch)\n        }\n    }\n}\n\nexport default \nconnect(matchStateToProps, matchDispatchToProps)(HomePage);\n<\/pre>\n<p>We are now done with the code part of our application. In the next section, we look at how to run and see the application in action.<\/p>\n<h2 class=\"wp-block-heading\">5. Running the Application<\/h2>\n<p>We need to make some changes to our start command in the package.json. The changes ensure both the server-side API and the client code are launched in parallel. There are utilities available out there to do this, but for this example, I just used the start command instead. Let us modify the start command to look like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>package.json<\/em><\/span><\/p>\n<pre class=\"brush: js;\">...\n\"start\": \"start react-scripts start &amp;&amp; start node api\/index.js\",\n...\n<\/pre>\n<p>Now running the command npm start launches our app and the result looks like below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"432\" height=\"439\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/02\/ScreenGrabReactJSReduxApp.jpg\" alt=\"ReactJS and Redux - Screen Grab\" class=\"wp-image-102013\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/02\/ScreenGrabReactJSReduxApp.jpg 432w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/02\/ScreenGrabReactJSReduxApp-295x300.jpg 295w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/02\/ScreenGrabReactJSReduxApp-70x70.jpg 70w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><figcaption>Screen Grab<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">6. Download the Source Code<\/h2>\n<p>This was a ReacJS and Redux Tutorial<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/02\/JCG-ReactJS-and-Redux-Tutorial.zip\"><strong>ReactJS and Redux Tutorial<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we look at using the Redux library with ReactJS. Redux, in a gist, centralizes state management. It provides APIs and patterns to manipulate the state in a predictable way. This leads to consistent application behavior. Wherein for the same set of changes we get the same resultant state every time, the change &hellip;<\/p>\n","protected":false},"author":82952,"featured_media":92051,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1903],"tags":[1919,1974],"class_list":["post-101844","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-js","tag-reactjs","tag-redux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ReactJS and Redux Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this post, we look at using the Redux library with ReactJS. Redux, in a gist, centralizes state management. It provides APIs and patterns to manipulate\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ReactJS and Redux Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this post, we look at using the Redux library with ReactJS. Redux, in a gist, centralizes state management. It provides APIs and patterns to manipulate\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-12T14:00:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Siddharth Seth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Seth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html\"},\"author\":{\"name\":\"Siddharth Seth\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/09c54717e2cc7956aa8a2df61330f18c\"},\"headline\":\"ReactJS and Redux Tutorial\",\"datePublished\":\"2020-02-12T14:00:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html\"},\"wordCount\":1073,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"keywords\":[\"Reactjs\",\"Redux\"],\"articleSection\":[\"React.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html\",\"name\":\"ReactJS and Redux Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"datePublished\":\"2020-02-12T14:00:36+00:00\",\"description\":\"In this post, we look at using the Redux library with ReactJS. Redux, in a gist, centralizes state management. It provides APIs and patterns to manipulate\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-and-redux-tutorial.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"React.js\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\\\/react-js\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"ReactJS and Redux Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/09c54717e2cc7956aa8a2df61330f18c\",\"name\":\"Siddharth Seth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"caption\":\"Siddharth Seth\"},\"description\":\"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/siddharth-seth-240180\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/siddharth_seth1980\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ReactJS and Redux Tutorial - Java Code Geeks","description":"In this post, we look at using the Redux library with ReactJS. Redux, in a gist, centralizes state management. It provides APIs and patterns to manipulate","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html","og_locale":"en_US","og_type":"article","og_title":"ReactJS and Redux Tutorial - Java Code Geeks","og_description":"In this post, we look at using the Redux library with ReactJS. Redux, in a gist, centralizes state management. It provides APIs and patterns to manipulate","og_url":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-02-12T14:00:36+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","type":"image\/jpeg"}],"author":"Siddharth Seth","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Siddharth Seth","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html"},"author":{"name":"Siddharth Seth","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/09c54717e2cc7956aa8a2df61330f18c"},"headline":"ReactJS and Redux Tutorial","datePublished":"2020-02-12T14:00:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html"},"wordCount":1073,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","keywords":["Reactjs","Redux"],"articleSection":["React.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html","url":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html","name":"ReactJS and Redux Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","datePublished":"2020-02-12T14:00:36+00:00","description":"In this post, we look at using the Redux library with ReactJS. Redux, in a gist, centralizes state management. It provides APIs and patterns to manipulate","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/reactjs-and-redux-tutorial.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"React.js","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript\/react-js"},{"@type":"ListItem","position":5,"name":"ReactJS and Redux Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/09c54717e2cc7956aa8a2df61330f18c","name":"Siddharth Seth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","caption":"Siddharth Seth"},"description":"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.","sameAs":["https:\/\/www.linkedin.com\/in\/siddharth-seth-240180\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/siddharth_seth1980"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/101844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/82952"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=101844"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/101844\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/92051"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=101844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=101844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=101844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}