Redux Flashcards

(10 cards)

1
Q

What is Redux?

A

A state manager for React applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three key concepts in Redux?

A

Store (eg CounterState/UserState)
Actions (eg increment, decrease)
Reducers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Stores

A

import {configureStore} from “@reduxjs/toolkit”

export const store = configureStore({reduce: {},})

export type RootState = ReturnType<typeof>
export type AppDispatch = typeof store.dispatch</typeof>

_——————————————
RootState type gives us type checks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Actions

A

Actions are things you can do to overwrite the state.

Actions have types (strings) and optional payloads of information.

Payloads are an optional variable you can add to actions (eg if incrementingByAmount)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Reducers

A

Reducers use the type of action to know what to do to the store.

Reducers don’t ever directly change the state (which is immutable), it makes updates to a copy of the state and overwrites the entire state..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Providers

A

We need to provide the store with a provider to our app component .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

createSlice

A

Slices are used for managing parts of your stores.

Note: states are immutable but when you use createSlice it allows you to write mutating code e.g. in the increment below.
_______________________________

const counterSlice = createSlice){name: “counter”, initialState, reducers: { increment: (state) => state.value +=1} , }, })

export const {increment, decrement} = counterSlice.actions
export default counterSlice.reducer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

useSelector

A

This is how we get the state values in a component.
useSelector is a redux hook

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

useDispatch

A

This is how we dispatch actions to influence the store.
useDispatch is a redux hook.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

async reducers

A

these use createAsyncThunk and go in extraReducers instead of reducers in creating the slice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly