React Redux Tutorials - 13 - Redux Thunk Middleware

Поділитися
Вставка
  • Опубліковано 5 лис 2024

КОМЕНТАРІ • 222

  • @ameetshrestha6424
    @ameetshrestha6424 5 років тому +85

    One of the best redux tutorial till now. Had been searching for the one with a very good and detail explanation and found yours. Thanks man. Really appreciate a lot. Keep uploading more.

  • @21agdmnm
    @21agdmnm 4 роки тому +71

    The moment you put dispatch as an argument in return function inside action creator my brain had a short circuit...

    • @arniyhjs
      @arniyhjs 4 роки тому +1

      sorry about that, I had the reaction with time it will finally stick

    • @lamargtv2572
      @lamargtv2572 3 роки тому +1

      So did i

    • @vaclavvlcek4527
      @vaclavvlcek4527 3 роки тому +1

      Same for me, I can't get it what that dispatch as an argument is supposed to be :) But I tried that without it and it didn't work, so it seems to be necessary there.

    • @brunagobi7393
      @brunagobi7393 3 роки тому +1

      same here

    • @noi1989
      @noi1989 3 роки тому +15

      dispatch() requires a plain action object. Our action creators normally return just that. A plain object.
      Redux-thunk allows us to use a function in our dispatch. The middleware can discern between an object and a function. If it is a function returned from our action creator, that return function is invoked and it is passed the dispatch function from the store as an argument. This way, we have dispatch available to us right in our object creator. We’re still dispatching plain objects to our reducers at the end of it all, we’re just moving the dispatch to the action creator function, so we can introduce those side effects like additional logic, or asynchronous calls.
      So I guess in a way we are ‘lifting’ the store.dispatch() method into the action creator function and calling it there. The reducers know no different. They’re still getting plain objects.

  • @acmeacademiccouncilofmecha7569
    @acmeacademiccouncilofmecha7569 9 місяців тому +25

    Now use
    const thunkMiddleWare = require("redux-thunk").thunk;
    instead of
    const thunkMiddleWare = require("redux-thunk").default;

  • @jpesmar
    @jpesmar 3 роки тому +11

    This whole channel is absolute gold.
    Thank you so much for making these videos. You're saving lives.

    • @andaeiii
      @andaeiii 3 роки тому

      i subscribed right away... i'm sooo confident of redux like mad...

  • @azharmobeen
    @azharmobeen 4 роки тому +10

    That's what I was looking for and I have completed all the tutorials for ReactJs and now this series of tutorials and I loved it soo much.

    • @sidvyas2302
      @sidvyas2302 4 роки тому +1

      Bro..do you have good tutorials for React Routing ?

    • @iuliiasiriakivska2209
      @iuliiasiriakivska2209 4 роки тому

      @@sidvyas2302 did you find anything good on React Routing yet? Thanks in advance

  • @nickharalampopoulos
    @nickharalampopoulos 4 роки тому +8

    Excellent work! After struggling to get Redux for weeks, it took only 13 of your videos to make it clear to me. Thank you

  • @shahipapon833
    @shahipapon833 2 роки тому +2

    At least someone exists in this world who has the capacity to make redux clearly understand 😍😍😍😍😍

  • @rahulpatidarbhooteshwar9187
    @rahulpatidarbhooteshwar9187 4 роки тому +1

    Superb. Redux explained in most simple & intuitive way.
    I have following queries regarding current video?
    - Can we completely avoid redux-thunk, do the async stuff out of the redux system & just update the redux state whenever we need ?
    - Do we really need that action creator wrapper "fetchUsers" that returns the actual function. Can't we pass that function ref (no actual call) directly to our dispatch call ?

  • @moderncloth
    @moderncloth 3 роки тому +4

    This is blowing my mind man. I'm actually getting this. Much love.

  • @amithbhagat
    @amithbhagat 5 років тому +1

    Thanks a lot for such a clear explanation on Redux, never understood the Thunk like this before, 7:35 summarizes the key concept of middleware.

    • @cjanesfull
      @cjanesfull 4 роки тому +2

      "Thunk returns a function instead of an action so that it can perform async tasks."

  • @alhanampi00
    @alhanampi00 4 роки тому +7

    Thank you a lot for your tutorials, for they are the best react/redux ones I've watched!

  • @ChrisLau90
    @ChrisLau90 5 років тому +9

    Love your videos! They're always clear and concise. You've helped me out so much!

  • @akmv7647
    @akmv7647 2 роки тому +2

    The best redux tutorial ever!! So simple, clear, concise and to the point! 👌

  • @rasulrukh2907
    @rasulrukh2907 4 роки тому +1

    Thank you very much, i was trying to use Redux with React Native and was confused. the best redux for free tutorial so far

  • @paterfamiliasgeminusiv4623
    @paterfamiliasgeminusiv4623 7 місяців тому +8

    I got an error that said sth like "middleware is not a function". Fixed by replaceing require("redux-thunk").default with require("redux-thunk").thunk.

  • @djwave28
    @djwave28 4 роки тому +2

    This course is phenomenal. Clear as glass!

  • @SimPwear84
    @SimPwear84 4 роки тому +5

    Wow, amazing series! I am now confident in Redux, thank you

  • @Scartizz1
    @Scartizz1 3 роки тому +2

    Everyone who gets Error message: "UnhandledPromiseRejectionWarning: ReferenceError: error is not defined..." or like this:
    Its because we have to put are arguments into the functions:
    const usersSuccess = (users) => {
    return {
    type: USERS_SUCCESS,
    payload: users,
    }
    }
    const usersFailure = (error) => {
    return {
    type: USERS_FAILURE,
    payload: error,
    }
    }

  • @AnandKumarReddyRagipindi
    @AnandKumarReddyRagipindi 8 місяців тому +5

    const thunkMiddleWare = require("redux-thunk").default; is getting error
    and the Error is : const chain = middlewares.map((middleware) => middleware(middlewareAPI));
    Solution is : const thunkMiddleWare = require("redux-thunk").thunk;

    • @miusoft
      @miusoft 8 місяців тому

      thank you!

  • @mridulkhurana4093
    @mridulkhurana4093 4 роки тому

    you are the best teacher i have ever come across in any technical stack

  • @sc0820
    @sc0820 4 роки тому +6

    This is most difficult part for understanding redux as a whole in my point of view.
    In my opinion, async action creator is an action creator that controls different dispatches asynchronously, in this case, by axios and thunk( create space for non-pure function(otherwise the dispatches cannot be put insides) inside an action creator) .
    Hope this may help a bit.

  • @nejuspesnejsi
    @nejuspesnejsi 4 роки тому +3

    This 8 minute long video took me 2 full days to grasp!!!

    • @danielvnzla6278
      @danielvnzla6278 4 роки тому

      lol? but this is the most easy y comprensible tutorial i ever seen after now.....

  • @bmejia220
    @bmejia220 3 роки тому

    Thank you for this great tutorial video! It is helpful for learning to use redux and async call, I like very much how you put the store, actions and reducers in one file. It makes the code very transparent and easy to understand. Great job, and thank you!!!

  • @quangtranoannhat2930
    @quangtranoannhat2930 3 роки тому

    one of the best tutorial redux that i have learned

  • @prisinha
    @prisinha 2 роки тому

    make an API call and Dispatch the appropriate Action 1:11 npm install axios redux-thunk 1:33 redux.applyMiddleware 1:44 pass second param to createStore 2:02 import redux-thunk 2:12 pass param redux-thunk to applyMiddleware 2:22 import axios 2:33 async actionCreator

  • @SirVib
    @SirVib 4 роки тому

    Finally got it, blew my mind. Thanks for this, Vishwas.

  • @abhidubey2965
    @abhidubey2965 4 роки тому

    I was stuck in between then I just paused the video saw my code again and understood it completely. Thanks to you the way you teach It all makes sense to me. and sometimes I try to write code before you as I know I will understand that with your help if stuck

  • @ghostyshka
    @ghostyshka 8 місяців тому +3

    if you learn it today this will dont work because you get TypeError: middleware is not a function

  • @abdullahbabor4876
    @abdullahbabor4876 2 роки тому

    make some paid courses at a student-friendly price. I am pretty sure you will rock this market. you are spending your time, you deserve the value.

  • @sunday-ucheawaji7966
    @sunday-ucheawaji7966 2 роки тому

    Thanks a lot for you clear and concise explanation. Am so glad learning from you

  • @josephijezie5486
    @josephijezie5486 4 роки тому +1

    I thank God I discovered your video, you're a guru------- joseph from Nigeria

  • @vipuldev1283
    @vipuldev1283 3 роки тому

    redux was a nightmare for me until this playlist showed up

  • @driftking1045
    @driftking1045 3 роки тому +6

    Why did we use ".default" method while importing redux-thunk ?

  • @MRABDULALI-123
    @MRABDULALI-123 2 роки тому

    love the way you gave concept

  • @isakawilliam
    @isakawilliam 3 роки тому

    this channel is so underated

  • @yashm05
    @yashm05 3 роки тому

    Great Explanation. God bless you buddy 😇️ Love from INDIA ❤️

  • @yashwanthv1092
    @yashwanthv1092 5 років тому +2

    Many thanks Vishwas. Always been a fan of your training videos. One doubt though, why don't you put semicolons in any of the statements!!!

    • @yogibaba007
      @yogibaba007 5 років тому

      In JavaScript, automatic semicolon insertion (ASI) allows one to omit a semicolon at the end of a line. But use it wisely as there are certain scenarios where omitting semicolons can be a cause of error in your code

  • @mdbicky9460
    @mdbicky9460 3 роки тому

    such an awesome series I loved it man keep up the good work

  • @muhammadsafvankv9394
    @muhammadsafvankv9394 8 місяців тому +2

    after doing this i got an error, const chain = middlewares.map((middleware) => middleware(middlewareAPI));
    TypeError: middleware is not a function. please fix this

    • @OtepArc
      @OtepArc 8 місяців тому +2

      Solution is : const thunkMiddleWare = require("redux-thunk").thunk; instead of default

    • @NeazTech
      @NeazTech 8 місяців тому +1

      Thanks a lot! It works now nicely @@OtepArc

  • @nipunmilinda
    @nipunmilinda 9 місяців тому +2

    error :
    error "middleware is not a function"
    Solution :
    const thunkMiddleware = require('redux-thunk').thunk;

  • @MAzeemSidd
    @MAzeemSidd 3 роки тому +5

    what does .default do after require() function?
    for example require('redux-thunk').default

  • @VeereshHiremath-b9q
    @VeereshHiremath-b9q 11 місяців тому

    Vishwas you did all the sessions awesome and next level , if you have time kindly make the series on redux-saga also , i hope it also appear this series in your video play list in upcoming days thank you brother.

  • @PascalHeimlicher
    @PascalHeimlicher 5 років тому +8

    Can you please make the same exercise with Redux Saga instead of Redux Thunk? That would be amazing!

  • @Gjacolby83
    @Gjacolby83 4 роки тому

    Your explanation of thunks is A1. Thanks for this video.

  • @Aziz.Ahmed95
    @Aziz.Ahmed95 Рік тому

    Really appreciate your work thanks man for this great tutorial keep up the good work Sir! 🙂🙌

  • @mayurmahajan1503
    @mayurmahajan1503 4 роки тому +3

    nice tutorial! btw, for some reason, your voice sounds like of an army man :-)

  • @danieltkach2330
    @danieltkach2330 3 роки тому +11

    I felt that "dispatch" came all of a sudden. At the point of watching this I'm not understanding it. Could anybody shed some light please?

    • @Zealotux
      @Zealotux 3 роки тому +4

      Look more into Redux before trying to learn about Thunks, the dispatch call here is just to actually call the action creator (fetchUsers) on the store, not calling store.dispatch would be like declaring a function without ever using it.

  • @simeonieroteev4555
    @simeonieroteev4555 4 роки тому

    Very useful video! You have a nice explanation over the things!

  • @israelnoah18
    @israelnoah18 2 роки тому

    Nice tutorial...quick question I have not seen where the thunk middle ware connects or rather has a relationship with the fetchUsers function

  • @edwardslayd7816
    @edwardslayd7816 Рік тому

    You are a legend sir!

  • @Dylanbforthree
    @Dylanbforthree 4 роки тому +1

    Seriously good tutorial. Thank you for the upload

  • @femmytedreycryptoworld7875
    @femmytedreycryptoworld7875 9 місяців тому +1

    Am i the only one getting typeerror: middleware is not a function? I've been trying to get rid of this for the past 4 hours, but i couldn't

    • @josephkoh1562
      @josephkoh1562 8 місяців тому

      You need to use const thunkMiddleware = require("redux-thunk").thunk;, not const thunkMiddleware = require("redux-thunk").default; with redux-thunk since version 3

  • @anoopvasudevan
    @anoopvasudevan 4 роки тому +2

    This is great!
    Console logs are created by the middleware - correct?

    • @curious_catx
      @curious_catx 3 роки тому

      yes redux-logger creates those console logs.

  • @aparupaghoshal2387
    @aparupaghoshal2387 2 роки тому

    It would be really helpful if you could make tutorial for Redux Saga. Your tutorial videos are extremely helpful for developers like us. Thanks a ton!

  • @swapnilkshirsagar4779
    @swapnilkshirsagar4779 10 місяців тому +1

    TypeError: middleware is not a function
    i am getting this error from several days cant find solution

    • @NeazTech
      @NeazTech 8 місяців тому +1

      Solution is : const thunkMiddleWare = require("redux-thunk").thunk; instead of default

  • @chellecanale3178
    @chellecanale3178 2 роки тому +3

    Hi, I got nothing when I tried to run the node asyncActions.js, there are no error either in the console.

    • @seannaify
      @seannaify 2 роки тому +2

      I have the same, I didn't invoke the function with a ()

    • @rishavbhattacharyya3929
      @rishavbhattacharyya3929 2 роки тому

      @@seannaify thanks for the help mate.

  • @gvchowdary7591
    @gvchowdary7591 4 місяці тому +1

    Since version 3
    const thunkMiddleware = require('redux-thunk').thunk instead of const thunkMiddleware = require('redux-thunk').default

    • @keifer7813
      @keifer7813 4 місяці тому

      Man, thank you. I spent way too long trying to debug it when I should have just came to the comments 🤦‍♂️

  • @basmabob2498
    @basmabob2498 2 роки тому

    👏👏Thank u so much for this amazing tuto

  • @subhashgn1775
    @subhashgn1775 3 роки тому

    Thank you Vishwas for your great effort to give the quality content. I Have question, "Reducers must not do any asynchronous logic, calculate random values, or cause other "side effects" but how these middleware achieve the asynchronous logic integration.

  • @TheSudoCode
    @TheSudoCode 4 роки тому +1

    that's awesome bro. keep it up for sure

  • @davronnormominov
    @davronnormominov 2 роки тому

    Thank you for great Redux tutorial

  • @rutvikpatel3115
    @rutvikpatel3115 4 роки тому

    Thank you sir . I really like your explanation and the examples to took.

  • @naseeb3661
    @naseeb3661 3 роки тому

    Thank you for this amazing tutorial!!😃😃

  • @dibendu.s
    @dibendu.s 3 роки тому

    Literally. LITERALLY, my first ever brain fart when "dispatch" suddenly showed up. And more so when it wasn't even in the guest list.

  • @anjanasanthosh1040
    @anjanasanthosh1040 2 місяці тому

    Thanku for all your videos

  • @CHIRANJIBNANDY1
    @CHIRANJIBNANDY1 4 роки тому

    Awesome, now everything looks much understandable.

  • @gane27
    @gane27 3 роки тому +2

    Hi Viswas,
    Im getting this error, im not able resolve, any idea.?
    { loading: true, users: [], error: '' }
    {
    loading: false,
    users: [],
    error: 'self signed certificate in certificate chain'
    }

  • @arpitadutta1790
    @arpitadutta1790 3 роки тому

    Thank you for making so understandable videos. Please make a video about redux -saga. As soon as possible.

  • @abhishekrawat8579
    @abhishekrawat8579 3 роки тому

    redux just blows away my mind🤯

  • @kaweesimatia1199
    @kaweesimatia1199 9 місяців тому +1

    How can i solve the error "middleware is not a function"

    • @NeazTech
      @NeazTech 8 місяців тому +1

      Solution is : const thunkMiddleWare = require("redux-thunk").thunk; instead of default

  • @sufiyanhabib4431
    @sufiyanhabib4431 2 роки тому

    Splendid explanation!!!!

  • @prisinha
    @prisinha 2 роки тому

    3:00 redux-thunk helps to return a function instead of an action object

  • @manisankarkantipudi2141
    @manisankarkantipudi2141 4 роки тому

    Thank you for clear explanation

  • @maniratnaguptayekkala387
    @maniratnaguptayekkala387 2 роки тому

    const store = createStore(reducer, applyMiddleware(thunkMiddleware, logger)) -------> we can give mutiple args to middleware. Just tried

  • @vegeta00766
    @vegeta00766 5 років тому

    Eagerly waiting for more!

  • @eleazarfederio1718
    @eleazarfederio1718 3 роки тому

    nice, clear explaination sir

  • @jamezjaz
    @jamezjaz 3 роки тому

    Apt!
    Thank you, Vishwas

  • @RiotThanos
    @RiotThanos 2 роки тому

    Thanks this video realy helped

  • @jonsnow9246
    @jonsnow9246 3 роки тому

    thunk allows action creator to return function that does side effects i.e. call to API

  • @arvindsundararaj4180
    @arvindsundararaj4180 10 місяців тому +1

    still i'm getting this error const chain = middlewares.map((middleware) => middleware(middlewareAPI));
    ^
    TypeError: middleware is not a function

    • @srayoanray7310
      @srayoanray7310 10 місяців тому

      Write
      const thunkMiddleware = require ('redux-thunk'). thunk
      Instead of
      const thunkMiddleware = require ('redux-thunk'). default

  • @ProgrammingWithProject
    @ProgrammingWithProject 2 роки тому +1

    How the dispatch (fetchuser()) call automatically internal function

  • @pagadalasrinivas5487
    @pagadalasrinivas5487 3 роки тому +3

    When i' am running the application it throws this error in the console UnhandledPromiseRejectionWarning: ReferenceError: error is not defined
    would any one sort out the problem i'am facing?

    • @shivanshuamitabh831
      @shivanshuamitabh831 3 роки тому

      have you sorted it out?

    • @shivanshuamitabh831
      @shivanshuamitabh831 3 роки тому

      i am also getting the same error

    • @Scartizz1
      @Scartizz1 3 роки тому

      const usersSuccess = (users) => {
      return {
      type: USERS_SUCCESS,
      payload: users,
      }
      }
      const usersFailure = (error) => {
      return {
      type: USERS_FAILURE,
      payload: error,
      }
      }

  • @iuliiasiriakivska2209
    @iuliiasiriakivska2209 4 роки тому

    great job!! thank you!!

  • @reshabvaigankar2641
    @reshabvaigankar2641 4 роки тому +1

    awasome !!!! thank you

  • @dariend8659
    @dariend8659 3 роки тому +2

    Can someone please explain how the return function inside the fetchUsers( ) get the dispatch? I mean, the fetchUsers( ) does not have any parameter but how can the function inside it receive dispatch?

    • @lamargtv2572
      @lamargtv2572 3 роки тому

      yeah, i need the answerr also

    • @anandmishra1757
      @anandmishra1757 3 роки тому +5

      See the last line - dispatch(fetchUsers()) , when this line gets executed then redux middleware checks what it returns , if its object then execute as always , but if it returns a function then pass dispatch as an argument to that function .What happens is Rudux stores that function in a variable , then passes dispatch to it , u are confused because u think fetchUsers() is somehow passing dispatch , but in reality the returned function by fetchUsers has already been saved inside redux , which has dispatch to pass on to it .
      Also remember , returning a function with an argument will not give an error , it is just being returned , its not being called . Its been only called inside redux which has dispatch to pass on to it (and how redux got that retuned function ?? because of the last line i mentioned above)

  • @todaysrapsux123
    @todaysrapsux123 4 роки тому +1

    I finally understand 🙏🏻

  • @sanjaythorat
    @sanjaythorat 3 роки тому +1

    Do we really need redux-thunk here? Can't we directly invoke the function defined(returned) inside fetchUsers() and it will do the job for us?

    • @deepakjena6068
      @deepakjena6068 3 роки тому

      that's the whole point without using thunk you won't be able to. just go thru redux-thunk docs once you will understand.

  • @arijitkundu
    @arijitkundu 4 роки тому +1

    thunk you so much!

  • @panchaksharirc3176
    @panchaksharirc3176 5 років тому +2

    Vishwas, waiting for your next videos on react redux.

  • @eshwerhari4989
    @eshwerhari4989 9 місяців тому

    im getting an error "TypeError: middleware is not a function
    "

    • @bhoomikhurana32
      @bhoomikhurana32 9 місяців тому

      same,how did you solve it?

    • @eshwerhari4989
      @eshwerhari4989 9 місяців тому

      const thunkMiddleware = require('redux-thunk').default
      remove.default
      const store = createStore(reducer, applyMiddleware(thunkMiddleware.thunk))
      add .thunk inside the createStore

    • @jeff_404
      @jeff_404 5 місяців тому

      @@eshwerhari4989 Thank you.

  • @TechAsif24
    @TechAsif24 4 роки тому

    So Amazing!

  • @zaremakayasova8097
    @zaremakayasova8097 3 роки тому

    Thank you!

  • @mr.vbillionaire4193
    @mr.vbillionaire4193 Рік тому

    bhai yar tu english bohot acchi bolta hain our muze pata hain ki teri language hindi hain to agese videos hindi me banaya kar please bhai its request

  • @prisinha
    @prisinha 2 роки тому

    6:44 Test 7:33 Summary

  • @nihallloyd3398
    @nihallloyd3398 5 років тому +1

    Why do we make a get call in actions and not in reducers??? why to do only in actions not somewhere else. Is there any valid reason for that??

    • @lubosflorek1810
      @lubosflorek1810 4 роки тому

      Because it is something like design pattern. Reducers are responsible only for holding data and basic operations like, filter, omit... Call action could be in reducer, but in more complex code it would be a mess. And second problem would be middleware. Middleware is something between action creator and reducer so if you wanted to make async api call directly in reducer it would bypass any redux middleware, so you had to code something own that could process async calls.

  • @sangtonsing9722
    @sangtonsing9722 3 роки тому

    It works on decrement(when buying cake the number of cake decrease) but when trying to increment it malfunctions. Suppose numOfCakes-10 and when we buy it gives us 9 but when incrementing the number instead of giving 11 it gives us 101, 1011, 10111, 101111... Why? is it an intention bug?

  • @veeresh4441
    @veeresh4441 4 роки тому +1

    can we use the same logic in reducer to make axios request and get data , instead of thunk middleware

    • @ojko12345
      @ojko12345 4 роки тому

      Never use reducers for api calls

    • @veeresh4441
      @veeresh4441 4 роки тому +3

      @@ojko12345 I know we shouldn't use, but what's the reason behind it rather than having organized code

  • @Aziz.Ahmed95
    @Aziz.Ahmed95 Рік тому

    @Codevolution I have written the same code as it is but after running nothing in the output .
    const fetchUsers = () => {
    // reaching here
    return function(dispatch) {
    // not reaching here
    }
    }
    It is not going inside the return function(dispatch)
    can you please help me here what wrong I am doing?

    • @numanali8545
      @numanali8545 Рік тому

      its a common problem and no one has solution... i have searched everywhere lol

  • @siddharathadhumale3683
    @siddharathadhumale3683 4 роки тому

    You are the best ...

  • @abhaykumar9806
    @abhaykumar9806 4 роки тому +1

    Hi, Can u make videos on redux-saga as well? You explain good