Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learning Redux
Learning Redux

Learning Redux: Write maintainable, consistent, and easy-to-test web applications

eBook
€28.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learning Redux

Implementing the Elements of Redux

After getting the first taste of Redux, we will now go into more detail on the elements that make up Redux:

  • Actions: JavaScript objects, which describe state changes in the application
  • Action creators: Functions that take some arguments and return an action
  • Reducers: Functions that take the current state and an action, and return the new state
  • Store: The heart of Redux, which actually stores and guards your application state; we can subscribe to state changes in the store and dispatch actions to it

In this chapter, we will discuss how to implement these elements and how to put them together. Furthermore, we will create our first small project using Redux. It will be a simple blog that lists posts and reacts to user input when we click on these posts.

The Redux cycle

An action is dispatched

It all starts with a call to store.dispatch(action), which means that some action happened (user action, request resolved, and so on). An action is a plain object that describes what happened:

{ type: 'CREATE_POST', user: 'dan', text: 'hello world' }
It might help to think of the action as a kind of a log entry that tells we what happened, for example, Post hello...

Running code examples

All examples in this book use the new JavaScript syntax ES6/ES2015. Newer browser and Node.js versions already support most of this syntax (at the time of this writing, import/export is not supported anywhere, except Babel). If we want to support older versions of browsers or Node.js, we will need to transpile your code to the older JavaScript version ES5 via a tool, such as Babel (https://babeljs.io/). In addition to transpiling, Babel also allows you to use JSX syntax (an extension of JavaScript used with React) and even the future JavaScript syntax, where the proposal is already finalized, but not implemented in any engines yet.

Setting up a new project

This section explains how to set up a complete...

Implementing actions and action creators

In the first chapter, we learned how important actions are in Redux. Only actions can change the state of your application.

Actions in Redux are valid if they have a type property. The rest of the object structure is totally up to you. If you prefer using a standard structure, check out https://github.com/acdlite/flux-standard-action.

Redux actions are simple JavaScript objects with a type property, which specifies the name of the action.

Let's define a simple action, in the src/index.js file:

const createPost = { type: 'CREATE_POST', user: 'dan', text: 'New post' }
console.log(createPost)

Now, save the file. Webpack should automatically refresh the page after modifying and saving a source file (such as src/index.js).

...

Implementing reducers

In the first chapter, we learned about reducers, functions that take the current state and an action and return the new state of the application. As you now know, actions only describe what happened. Reducers use that information to compute the new state.

To be able to figure out state changes, we should first think about the state of our application. We have already done this in the first chapter, and our state looks as follows:

{ 
posts: [
{ user: 'dan', category: 'hello', text: 'Hello World!' },
{ user: 'des', category: 'welcome', text: 'Welcome to the blog' }
],
filter: 'hello'
}

As you can see, we have two separate sub-states in the main state object: posts and filter. This is a good hint for making two reducers: a postsReducer to handle the posts sub-state, and a filterReducer...

The store – combining actions and reducers

By now, we might be wondering what exactly Redux is (besides a set of principles and some helper functions). Essentially, Redux brings actions and reducers together. It provides a store, which contains the application state and provides some functions to do the following:

  • Access the application state: store.getState()
  • Dispatch actions: store.dispatch(action)
  • Register listeners: store.subscribe(listener)

According to the official documentation of Redux, Redux is a predictable state container for JavaScript apps.

The state container (store) is the heart of Redux: It contains your application state and does not allow external changes. Redux only allows changes through actions, which get passed to pure reducer functions. These restrictions that Redux enforces are what makes your application state predictable.

...

Summary

In this chapter, we first learned how to set up a project that is ready for Redux and the new JavaScript ES2015 syntax. Then, we implemented the basic elements of Redux and learned how ES2015 syntax makes implementing them easier. Finally, you also learned how to put a full Redux project together, as well as subscribe to state changes and dispatch actions.

In the next chapter, we will discuss how we can render user interfaces with React and use it together with Redux. Afterwards, we will build a full application with Redux and React.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Write applications that behave consistently, run in different environments (client, server and native), and are easy to test
  • Take your web apps to the next level by combining the power of Redux with other frameworks such as React and Angular
  • Uncover the best practices and hidden features of Redux to build applications that are powerful, consistent, and maintainable

Description

The book starts with a short introduction to the principles and the ecosystem of Redux, then moves on to show how to implement the basic elements of Redux and put them together. Afterward, you are going to learn how to integrate Redux with other frameworks, such as React and Angular. Along the way, you are going to develop a blog application. To practice developing growing applications with Redux, we are going to start from nothing and keep adding features to our application throughout the book. You are going to learn how to integrate and use Redux DevTools to debug applications, and access external APIs with Redux. You are also going to get acquainted with writing tests for all elements of a Redux application. Furthermore, we are going to cover important concepts in web development, such as routing, user authentication, and communication with a backend server After explaining how to use Redux and how powerful its ecosystem can be, the book teaches you how to make your own abstractions on top of Redux, such as higher-order reducers and middleware. By the end of the book, you are going to be able to develop and maintain Redux applications with ease. In addition to learning about Redux, you are going be familiar with its ecosystem, and learn a lot about JavaScript itself, including best practices and patterns.

Who is this book for?

This book targets developers who are already fluent in JavaScript but want to extend their web development skills to develop and maintain bigger applications.

What you will learn

  • • Understand why and how Redux works
  • • Implement the basic elements of Redux
  • • Use Redux in combination with React/Angular to develop a web application
  • • Debug a Redux application
  • • Interface with external APIs with Redux
  • • Implement user authentication with Redux
  • • Write tests for all elements of a Redux application
  • • Implement simple and more advanced routing with Redux
  • • Learn about server-side rendering with Redux and React
  • • Create higher-order reducers for Redux
  • • Extend the Redux store via middleware

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 31, 2017
Length: 374 pages
Edition : 1st
Language : English
ISBN-13 : 9781786462398
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Aug 31, 2017
Length: 374 pages
Edition : 1st
Language : English
ISBN-13 : 9781786462398
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
React Design Patterns and Best Practices
€36.99
React and React Native
€41.99
Learning Redux
€41.99
Total 120.97 Stars icon

Table of Contents

12 Chapters
Why Redux? Chevron down icon Chevron up icon
Implementing the Elements of Redux Chevron down icon Chevron up icon
Combining Redux with React Chevron down icon Chevron up icon
Combining Redux with Angular Chevron down icon Chevron up icon
Debugging a Redux Application Chevron down icon Chevron up icon
Interfacing with APIs Chevron down icon Chevron up icon
User Authentication Chevron down icon Chevron up icon
Testing Chevron down icon Chevron up icon
Routing Chevron down icon Chevron up icon
Rendering on the Server Chevron down icon Chevron up icon
Solving Generic Problems with Higher-Order Functions Chevron down icon Chevron up icon
Extending the Redux Store via Middleware Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(3 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Just Some Guy Jun 01, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is THE BOOK YOU WANT to learn Redux. I just read it, and it answered all the questions I had about Redux from other sources. Filled with great, in depth examples, clear explanations, and just the right level of technical depth, this book should be on every React developer's shelf. As a bonus, it uses all the latest ES6 conventions, as well as delving into how to approach essential concerns like testing, authentication, server-side rendering, and more. I don't usually gush about tech books, but nobody has reviewed this book yet so I want to make my opinion clear. THIS BOOK IS A MUST READ if you're a serious developer and you want to work with Redux. Buy it. Read it. Thank me later. ;-)
Amazon Verified review Amazon
tmok2000 Jul 20, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a very well written book. The author is clearly very knowledgeable about the subject, as well as the use of the JavaScript/ECMAScript language. Not only he explains everything well, his code is beautifully written, too. I really appreciate that, as I always strive to write beautiful code myself. However, as anything in a fast moving technological world, the Webpack config part of the book is already outdated. I had to work a little harder to make it work with Webpack 4, but it's all good now. Also, Babel now has a new preset called "env", which the book doesn't use. It still advises to use the es2015 preset. These are minor issues. The book overall is very good, and I certainly learned a lot from it.
Amazon Verified review Amazon
Jose Garcia Jun 03, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book delivers in a big way! The author begins with the foundations of Redux and goes into practical details to explain the concepts that build Redux and the mindset behind it. By doing a simple project and scaling that project throughout the book, the reader gains deeper insight, best practices, and practical applications that can be applied to the reader's projects.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.