Chaining Callbacks

Learn how to chain callbacks, where one callback result triggers another callback without further direct user influence.

Chained callbacks

As the name suggests, a chained callback is a technique used to bind/link/chain callback functions together, in which we use the output of a particular callback function as the input to a successive callback function. Perhaps the best example of a chained callback could be in the implementation of a conditional dropdown menu.

In a conditional dropdown for an online store, we might want the user to be able to select either Sunglasses, T-shirts or Hats. Suppose they choose Sunglasses: From this point onward, we’d like to only show different sunglasses sub-categories (e.g., “Ray Ban Sunglasses,” “Oakley Sunglasses,” etc.). It would be a nuisance to the user to still show every sub-category for T-shirts and Hats as they never asked for those categories.

Get hands-on with 1200+ tech skills courses.