V
V
vimirtv2020-12-05 18:07:32
typescript
vimirtv, 2020-12-05 18:07:32

How to type action in Redux thunk?

I'm just getting started with TypeScript. I have an action that returns some data to a component that I don't need to store in the store.

type responseExample = {
a: number
}

export const createCatalog = (data: FormData) => {
    return async (dispatch: Dispatch<CatalogDispatchTypes>) => {
        return await $axios.post<responseExample >(`/Catalog/Create`, data)
        .then(response => {
            return response.data
        })
        .catch(e => {
            throw e
        })
    }
}


I would like to have the type I need returned when importing createCatalog. And the query was of type responseExample

const qeury = dispatch(createCatalog({a: 1, b: 2}))

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