P
P
ParseMeBaby2022-03-06 14:08:17
typescript
ParseMeBaby, 2022-03-06 14:08:17

How to properly pass data to React Redux TypeScript?

There is an array of objects, you need to make sure that when the onClick event occurs, the object is added to a specific array.
types.ts

export interface ImagesState {
    images?: any[];
    loading?: boolean;
    error?: null | string;
    page?: number;
    limit?: number;
    pages?: any[];
    selected?: any[];
    current?: null | object;
}
interface SetImagesSelected {
    type: ImagesActionTypes.SET_IMAGES_SELECTED,
    payload: object
}
export type ImagesAction = SetImagesSelected

action-creator/images.ts
export const setImagesSelected = (current: object): ImagesAction => {
    return {type: ImagesActionTypes.SET_IMAGES_SELECTED, payload: current}
}

reducer
case ImagesActionTypes.SET_IMAGES_SELECTED:
            return {...state, selected: [...action.payload]}


logic: I throw the current object into the selected array (I can’t understand why it doesn’t work)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question