Questions tagged [redux-toolkit]

Redux Toolkit (RTK) is the standard approach for writing Redux logic. It provides utilities to simplify several common Redux use cases, including store setup, defining reducers, immutable update logic, and even creating entire "slices" of state at once.

Redux Toolkit (RTK) is the standard approach for writing Redux logic. It provides utilities to simplify several common Redux use cases, including store setup, defining reducers, immutable update logic, and even creating entire "slices" of state at once.

Redux Toolkit was originally created to help address three common concerns about Redux:

  • "Configuring a Redux store is too complicated"
  • "I have to add a lot of packages to get Redux to do anything useful"
  • "Redux requires too much boilerplate code"

It provides tools that abstract over the setup process for Redux and handle the most common use cases, as well as include some useful utilities that will let the user simplify their application code.

RTK is beneficial to all Redux users. Whether you're a brand-new Redux user setting up your first project, or an experienced user who wants to simplify an existing application, Redux Toolkit can help you make your Redux code better.

3505 questions
1
vote
2 answers

Javascript imports (redux toolkit)

In the official redux toolkit documentation/tutorial, there's this file (counterSlice.js) import { createSlice } from '@reduxjs/toolkit' export const counterSlice = createSlice({ name: 'counter', initialState: { value: 0 }, reducers: { …
Wasteland
  • 4,889
  • 14
  • 45
  • 91
1
vote
2 answers

React @redux/toolkit not re-rendering component when state is updated

Codesandbox: https://codesandbox.io/s/condescending-wiles-funk0?file=/src/App.js Problem: When I update the state of my store the components are not re-rendered. In the above example you can see from the console that the data is correctly fetched,…
devamat
  • 2,293
  • 6
  • 27
  • 50
1
vote
1 answer

How to partial migrate to react toolkit given current usage of Immutable.js?

I have a large app which uses React, Redux, and Immutable.js. I'd like to migrate to react-toolkit with its createSlice function, which looks really nice. The problem I have is that because of my usage of redux middleware for Immutable…
Kevin
  • 24,871
  • 19
  • 102
  • 158
1
vote
1 answer

How to use AppDispatch type in in Redux async thunk?

In my Redux async thunks, I want to use the AppDispatch type that is inferred as described here: https://redux.js.org/recipes/usage-with-typescript I followed the instructions here:…
thSoft
  • 21,755
  • 5
  • 88
  • 103
1
vote
1 answer

How to efficiently select a redux store slice

In a React/Hooks/ReduxToolkit application, what are the efficiency implications of selecting a slice of the redux store in the following two methods: Store Structure: const store: RootState = { students, courses, } students is a dictionary of…
Cesar N Mejia Leiva
  • 1,611
  • 1
  • 12
  • 18
1
vote
1 answer

redux store not found and not able to render a component for a specific path in React

I am implementing a password reset functionality in a MERN app. When a user enters the email address for which they want to reset the password, they get a rest password link in their mail. Now, when they visit that link, they should see the…
HKS
  • 526
  • 8
  • 32
1
vote
1 answer

Redux Toolkit says this snippet(19 lines) is shorter code (vs. original 12) confusion

I am reading this page getting into react-redux https://redux.js.org/introduction/getting-started I am very confused looking at the Basic Example which has 12 lines of code(excluding usage, imports, and comments) Then I read this line on the "Redux…
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
1
vote
1 answer

react- redux toolkit app issue when trying to get redux data into component

I am trying to add redux data into a component , and I am getting below issue in console.log when I try to check the redux data, could someone able to help me with this my redux slice is below . please check the bolded line it seems its causing the…
famo
  • 160
  • 1
  • 13
1
vote
1 answer

curentamount is not defined, no-undef, when I increment value using createSlice Reducer

In reduxSlice file, I am getting an error - 'curentamount' is not defined no-undef. Redux slice: import { createSlice } from '@reduxjs/toolkit' export const addtoSlice = createSlice({ name: 'addto', initialState: { curentamount: 0, }, …
famo
  • 160
  • 1
  • 13
1
vote
0 answers

How to run page integration tests with redux?

I have a page that I want to run tests against to check if certain functionality is enabled / disabled based on the existing state in Redux. I feel that whilst the current solution I have works, it looks messy in tests & I want to get a…
Jamie
  • 3,105
  • 1
  • 25
  • 35
1
vote
1 answer

Problem accessing state in React app using react-redux / redux-watch

I am trying to access the state.X of my store when Redux-watch store.subscribe() is triggered (by updating state.Y), but I can access just initial state values. I am using Redux-toolkit, React-redux, React-watch When I call the "print" function…
Jakub Piga
  • 66
  • 5
1
vote
1 answer

Linking objects to elements in react-flow-renderer/react-flow in redux store

I have been trying to connect the store to my existing toolkit the useStoreState acts as a useSelector I am not sure if it is ideal for my use case. I am wondering if there is a way to either connect the store directly to my existing redux toolkit…
Asif333
  • 47
  • 1
  • 6
1
vote
2 answers

REACT: put token from store into axios header

I'm pretty new to React and trying to add an JWT token to my headers for authorized api calls. // client.ts export const client = axios.create({ baseURL: URLS.local, responseType: 'json', timeout: 180000, }); const state =…
Han
  • 63
  • 11
1
vote
1 answer

react/redux app - TypeError: Cannot read property 'user' of undefined

I am creating a react app, when getting data from redux. I am facing the below error message in browser. please check and let me know what am I missing. I am using create-react-app redux-toolkit setup template to create the app Here is my…
famo
  • 160
  • 1
  • 13
1
vote
1 answer

I got Type-errors while converting my Slice.js file to ts (redux tool kit)

I just created my sample Redux tool kit with js files. now I am trying to convert them to typescript. some of the error is now fixed. but I have no idea how to fix the two errors below. Property 'name' does not exist on type 'void'. <<<< also for…
Jin Park
  • 371
  • 1
  • 9
  • 23
1 2 3
99
100