Redux - How to use react-hot-toast with async await Axios call
See original GitHub issuehey guys, I saw the other question about this but it did not help me. I have tried multiple ways to get this to work but cannot seem to make it work.
I tried this:
export const postVersionBulkAction = (args) => {
let url = `${apiBase}/smart-list/version/${args.versionId}/action`
let promise = queue.wrap(async (dispatch) => {
let params = { iabCategoriesActions: args.iabCategoriesActions }
const result = await axios.patch(url, params)
if (result.status === 200) {
}
})
toast.promise(promise, {
loading: 'Saving...',
success: 'saved',
error: 'error'
})
}
but that gives me an error: ‘TypeError: promise.then is not a function’
I’ve also tried this:
export const postVersionBulkAction = (args) => {
let url = `${apiBase}/smart-list/version/${args.versionId}/action`
return queue.wrap(async (dispatch) => {
try {
let params = { iabCategoriesActions: args.iabCategoriesActions }
const result = await axios.patch(url, params)
toast.promise(result, {
loading: 'Saving...',
success: 'saved',
error: 'error'
})
} catch (error) {
alert(error)
}
})
}
but i get ‘promise.then is not a function’ error on that one too.
I’ve also tried calling it like this:
const promise = props.postVersionBulkAction(params)
toast.promise(promise, {
loading: 'Saving...',
success: <b>saved!</b>,
error: <b>Could not apply.</b>
})
but that way always fires the success toast even if it fails.
Any idea how i could make this work?
PS. thanks for the awesome product! Other than this problem it has helped me so much, and I have succesfully removed thousands of lines of redux boilerplate because of this library. thanks again
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Use react-hot-toast with Promise & Axios - DEV Community
Use react -hot-toast with Promise & Axios ... default function App() { const fetchData = async () => { const response = await...
Read more >react toastify with redux from axios API - Stack Overflow
i fixed it and here is my code : // auth.js ( redux page ) export const login = createAsyncThunk( "/login", async ({...
Read more >Create smoking hot toast notifications in React with ... - Daily.dev
Smoking hot Notifications for React provides lightweight, customizable and beautiful by default notifications. Learn how to use it quickly ...
Read more >toast() API
toast () API. Call it to create a toast from anywhere, even outside React. Make sure you add the <Toaster/> component to your...
Read more >How to Use Async/Await with Axios in React | by Aditya Singh
Now, we want to make the same request using async / await . Let's do it! For a function to use await ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have you tried ensuring your
.catch
was first and.then
following it? Weirdly enough, that fixed this same issue for me.(I know this isn’t an Axios example, but the promise structure is relatively the same)
This worked for me