What is Re­dux mid­dle­ware?

Web Designer - - Tutorials -

With­out mid­dle­ware, Re­dux en­ables us to dis­patch ac­tions as ob­jects to then be sorted by the re­ducer. Some sit­u­a­tions, such as server com­mu­ni­ca­tion, re­quire a bit more con­trol over what gets sent and when.

Mid­dle­ware sits in be­tween the dis­patched ac­tion and the re­ducer, en­abling us to de­ter­mine if any ac­tion needs to be taken be­fore con­tin­u­ing. In the case of Re­dux Thunk, the mid­dle­ware knows that if it re­ceives a func­tion it should run it rather than carry on. It can then dis­patch its own ac­tions as needed.

Once it’s fin­ished with the ac­tion, it can pass it along to the re­ducer by call­ing ‘next’. This makes it pos­si­ble to com­bine dif­fer­ent mid­dle­ware to­gether with­out wor­ry­ing about los­ing ac­tions.

Mid­dle­ware is read­ily avail­able to be down­loaded and used as part of a third-party pack­age, but it can also be use­ful to keep other logic, such as an­a­lyt­ics and er­ror han­dling, away from the main ap­pli­ca­tion.

Newspapers in English

Newspapers from UK

© PressReader. All rights reserved.