React Redux Tutorials - 13 - Redux Thunk Middleware

Поделиться
HTML-код
  • Опубликовано: 17 ноя 2024

Комментарии • 223

  • @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 месяцев назад +27

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

  • @shahipapon833
    @shahipapon833 2 года назад +2

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

  • @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

  • @jpesmar
    @jpesmar 4 года назад +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

  • @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 ?

  • @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."

  • @moderncloth
    @moderncloth 3 года назад +4

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

  • @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

  • @akmv7647
    @akmv7647 2 года назад +2

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

  • @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,
    }
    }

  • @djwave28
    @djwave28 4 года назад +2

    This course is phenomenal. Clear as glass!

  • @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.....

  • @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!

  • @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.

  • @paterfamiliasgeminusiv4623
    @paterfamiliasgeminusiv4623 8 месяцев назад +9

    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.

  • @quangtranoannhat2930
    @quangtranoannhat2930 3 года назад

    one of the best tutorial redux that i have learned

  • @SirVib
    @SirVib 4 года назад

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

  • @josephijezie5486
    @josephijezie5486 5 лет назад +1

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

  • @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!!!

  • @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

  • @vipuldev1283
    @vipuldev1283 3 года назад

    redux was a nightmare for me until this playlist showed up

  • @prisinha
    @prisinha 3 года назад

    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

  • @AnandKumarReddyRagipindi
    @AnandKumarReddyRagipindi 9 месяцев назад +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 9 месяцев назад

      thank you!

  • @Gjacolby83
    @Gjacolby83 4 года назад

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

  • @yashm05
    @yashm05 3 года назад

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

  • @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

  • @MRABDULALI-123
    @MRABDULALI-123 2 года назад

    love the way you gave concept

  • @driftking1045
    @driftking1045 3 года назад +6

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

  • @PascalHeimlicher
    @PascalHeimlicher 5 лет назад +8

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

  • @ghostyshka
    @ghostyshka 8 месяцев назад +3

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

  • @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

  • @danieltkach2330
    @danieltkach2330 4 года назад +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!

  • @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.

  • @MAzeemSidd
    @MAzeemSidd 3 года назад +5

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

  • @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.

  • @mdbicky9460
    @mdbicky9460 3 года назад

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

  • @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!

  • @Aziz.Ahmed95
    @Aziz.Ahmed95 Год назад

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

  • @rutvikpatel3115
    @rutvikpatel3115 4 года назад

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

  • @arpitadutta1790
    @arpitadutta1790 3 года назад

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

  • @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'
    }

  • @Dylanbforthree
    @Dylanbforthree 4 года назад +1

    Seriously good tutorial. Thank you for the upload

  • @CHIRANJIBNANDY1
    @CHIRANJIBNANDY1 4 года назад

    Awesome, now everything looks much understandable.

  • @isakawilliam
    @isakawilliam 3 года назад

    this channel is so underated

  • @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.

  • @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.

  • @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.

  • @mayurmahajan1503
    @mayurmahajan1503 4 года назад +3

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

  • @muhammadsafvankv9394
    @muhammadsafvankv9394 9 месяцев назад +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 9 месяцев назад +2

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

    • @NeazTech
      @NeazTech 8 месяцев назад +1

      Thanks a lot! It works now nicely @@OtepArc

  • @abhishekrawat8579
    @abhishekrawat8579 3 года назад

    redux just blows away my mind🤯

  • @davronnormominov
    @davronnormominov 2 года назад

    Thank you for great Redux tutorial

  • @nipunmilinda
    @nipunmilinda 10 месяцев назад +2

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

  • @panchaksharirc3176
    @panchaksharirc3176 5 лет назад +2

    Vishwas, waiting for your next videos on react redux.

  • @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

  • @naseeb3661
    @naseeb3661 3 года назад

    Thank you for this amazing tutorial!!😃😃

  • @manisankarkantipudi2141
    @manisankarkantipudi2141 4 года назад

    Thank you for clear explanation

  • @edwardslayd7816
    @edwardslayd7816 Год назад

    You are a legend sir!

  • @basmabob2498
    @basmabob2498 2 года назад

    👏👏Thank u so much for this amazing tuto

  • @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,
      }
      }

  • @anjanasanthosh1040
    @anjanasanthosh1040 2 месяца назад

    Thanku for all your videos

  • @TheSudoCode
    @TheSudoCode 4 года назад +1

    that's awesome bro. keep it up for sure

  • @prisinha
    @prisinha 3 года назад

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

  • @maniratnaguptayekkala387
    @maniratnaguptayekkala387 2 года назад

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

  • @jonsnow9246
    @jonsnow9246 3 года назад

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

  • @eleazarfederio1718
    @eleazarfederio1718 4 года назад

    nice, clear explaination sir

  • @gvchowdary7591
    @gvchowdary7591 5 месяцев назад +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 🤦‍♂️

  • @jamezjaz
    @jamezjaz 3 года назад

    Apt!
    Thank you, Vishwas

  • @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

  • @ProgrammingWithProject
    @ProgrammingWithProject 2 года назад +1

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

  • @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)

  • @femmytedreycryptoworld7875
    @femmytedreycryptoworld7875 10 месяцев назад +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

  • @sanjaythorat
    @sanjaythorat 4 года назад +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 4 года назад

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

  • @sufiyanhabib4431
    @sufiyanhabib4431 3 года назад

    Splendid explanation!!!!

  • @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 5 лет назад

      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.

  • @kaweesimatia1199
    @kaweesimatia1199 10 месяцев назад +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

  • @vegeta00766
    @vegeta00766 5 лет назад

    Eagerly waiting for more!

  • @jaayaustin336
    @jaayaustin336 3 года назад

    Is there a reason why you usually dont use ES6 method of import?

  • @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

  • @mritunjaypathak251
    @mritunjaypathak251 4 года назад +1

    Can we use fetch api instead of axios??

  • @RiotThanos
    @RiotThanos 2 года назад

    Thanks this video realy helped

  • @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

  • @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

  • @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?

  • @Ibrahim__123
    @Ibrahim__123 2 года назад

    How can some configure the store with the thunk and applyMiddleware to get the same result as you did using configureStore in redux toolkit
    I tired some ways, none is giving the expected result at all like:
    * const store = configureStore({reducer})
    * const store = configureStore({reducer, middleware: [thunk, applyMidddleware]})
    * const store = configureStore({reducer, enhancers: [thunk]})
    None gave the same result as yours
    Kindly assist me out . Thanks for your impact in me.
    Working fine now..issue with my code with calling dispatch on the store
    i configure the store this way ...const store = configureStrore({reducer})
    my mistake store.dispatch(fetchUsers) instead of write store.dispatch(fetchUsers());

  • @abhaykumar9806
    @abhaykumar9806 4 года назад +1

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

  • @israelnoah18
    @israelnoah18 2 года назад

    And how is it that am not using store.dispatch but dispatch itself and it works??

  • @dragonaicolosocastro1328
    @dragonaicolosocastro1328 4 года назад +1

    Me encantó tu vídeo realmente explicas excelente

  • @nineironshore
    @nineironshore 3 года назад

    Can async code work inside of a normal reducer?

  • @arvindsundararaj4180
    @arvindsundararaj4180 11 месяцев назад +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

  • @rakeshkumaryadav1117
    @rakeshkumaryadav1117 Год назад

    In my code I getting error
    Cannot read properties of undefined (reading 'applymiddle'l

  • @piyush9555
    @piyush9555 4 года назад

    can't we use any other npm module to make GET request to API endpoint?

  • @pruthvihingu3733
    @pruthvihingu3733 3 года назад

    If I am using unsubscribe() method then I am not able to get users in the state object. Is it because of thunkMiddleware problem?

    • @Scartizz1
      @Scartizz1 3 года назад

      I think its because u did unsubscribe )