1616982131
Redux Is This Easy Now? (with Redux-toolkit)
⌨️ Source Code (to start tutorial)
https://github.com/hidjou/redux-toolkit-tutorial
⌨️ Source Code (complete)
https://github.com/hidjou/redux-toolkit-tutorial/tree/complete
#redux
1615623540
Redux Toolkit is an opinionated, batteries-included toolset for efficient Redux development. In this article, you will see why the Redux Toolkit deserves more attention in the React community.
React and Redux believed to be the best combo for managing state in large-scale React applications. However, with time, the popularity of Redux fallen due to;
With these issues, the creator of Redux Dan Abramov published the article called You Might Not Need Redux , which advises people to use Redux only when it needs and to follow other methods when developing less complex applications.
#redux-toolkit #redux #react
1595681400
Redux Toolkit popularity is growing every month. What exactly helps developers to write code faster, easier, more clearly? One of the helpers is createSlice
function. createSlice
takes an object of reducer functions, a slice name, and an initial state value and lets us auto-generate action types and action creators, based on the names of the reducer functions that we supply. It also helps you organize all of your Redux-related logic for a given slice into a single file.
It’s a function that deals with everything you need for each slice, do you remember using createAction
and createReducer
manually? Now it’s available in this specific slice function.
So what the returned object from createSlice
contains:
name
: a parameter that will be the prefix for all of your action typesinitialState
: the initial values for our reducerreducers
: it’s an object where the keys will become action type strings, and the functions are reducers that will be run when that action type is dispatched.The other benefit of using createSlice
is our files structure. We can put all of our Redux-related logic for the slice into a single file. You’ll see how to do it in our tutorial.
We have made basic Redux configuration with Redux Toolkit. But what is the most important benefit of using Toolkit? Definitely, it’s createSlice
function that you will probably use for most application you’re developing.
If you don’t want to start from zero, you can use our basic Redux configuration with Redux Toolkit.
To our previous little app with fake authorization, we’re gonna add a feature to show users data to logged user.
Firstly let’s create file src/store/users.js
and create our slice:
import { createSlice } from '@reduxjs/toolkit'
// Slice
const slice = createSlice({
name: 'users',
initialState: {
users: []
},
reducers: {
getUsers: (state, action) => {
state.users = action.payload;
},
},
});
export default slice.reducer
That’s basic slice configuration, it contains name
, initialState
and reducers
parameters.
Now let’s add actions. To keep it clear and simply add it in our slice’s file. We don’t have to write them individually in separate file anymore. We can export all the actions. the reducer, the asynchronous thunk and selector
that gives us access to state from any component without using connect
.
import { createSlice } from '@reduxjs/toolkit'
+ import { api } from '../api/index'
// Slice
const slice = createSlice({
name: 'users',
initialState: {
users: [],
},
reducers: {
usersSuccess: (state, action) => {
state.users = action.payload;
state.isLoading = false;
},
},
});
export default slice.reducer
// Actions
+ const { usersSuccess } = slice.actions
+ export const fetchUsers = () => async dispatch => {
+ try {
+ await api.get('/users')
+ .then((response) => dispatch(usersSuccess(response.data)))
+ }
+ catch (e) {
+ return console.error(e.message);
+ }
+}
#react #front-end-development #redux #software-development #startup #redux toolkit
1595688780
Do you have experience using React? Have you heard of Redux, but you’ve put off learning it because it looks very complicated and all the guides seem overwhelming? If that’s the case, this is the article for you! Contain your fear of containing state and come along with me on this relatively painless journey.
You must already know how to use React for this tutorial, as I will not be explaining any aspects of React itself.
Also, download Redux DevTools for Chrome or for FireFox.
In this tutorial, we will build a small blog app. It will fetch posts and comments from an API. I’ve created the same app with both plain Redux, and Redux Toolkit (RTK), the officially sanctioned toolset for Redux. Here are the links to the source and demos of both the plain and RTK versions.
Note: The applications are pulling from a real API via JSON Placeholder API. Due to rate limiting on CodeSandbox, the API may appear slow, but it has nothing to do with the Redux application itself. You can also clone the repository locally.
Redux is a state container for JavaScript applications. Normally with React, you manage state at a component level, and pass state around via props. With Redux, the entire state of your application is managed in one immutable object. Every update to the Redux state results in a copy of sections of the state, plus the new change.
Redux was originally created by Dan Abramov and Andrew Clark.
The downside to Redux is that there’s a lot of initial boilerplate to set up and maintain (especially if you use plain Redux without Redux Toolkit). A smaller application may not need Redux and may instead benefit from simply using the Context API for global state needs.
In my personal experience, I set up an application with Context alone, and later needed to convert everything over to Redux to make it more maintainable and organized.
Usually I don’t like to just make a list of terms and definitions, but Redux has a few that are likely unfamiliar, so I’m just going to define them all up front to make it easy to refer back to them. Although you can skip to the beginning of the tutorial section, I think it would be good to read through all the definitions just to get exposure and an idea of them in your head first.
I’ll just use the typical todo application, and the action of deleting a todo, for the examples.
#redux #react #tutorial #redux toolkit #programming
1622824320
Redux Toolkit is the official, opinionated, batteries-included toolset for efficient Redux development. Mark Erikson (@acmemarke), long-time Redux maintainer and avid blogger about all things web development showed us the potential of Redux in action with an awesome demo!
Some handy links you might encounter in the video:
➡️ https://blog.isquaredsoftware.com/2021/01/context-redux-differences/
➡️ https://blog.isquaredsoftware.com/2018/11/react-redux-history-implementation/
➡️ https://github.com/immerjs/immer
React All-Day is a long-format stream of fun and learning with React experts, and live coding from familiar names and faces from around the React world!
Eight awesome guests covered eight exciting topics from sessions on testing, data management, full-stack frameworks to programming concepts, and more.
React Wednesdays is a weekly chat show with the best and brightest from the React world. Join us live every Wednesdays to hang out and ask questions. Learn more about the show and upcoming episodes at https://www.telerik.com/react-wednesdays.
#redux #redux
1616982131
Redux Is This Easy Now? (with Redux-toolkit)
⌨️ Source Code (to start tutorial)
https://github.com/hidjou/redux-toolkit-tutorial
⌨️ Source Code (complete)
https://github.com/hidjou/redux-toolkit-tutorial/tree/complete
#redux