Let’s dig into how generators work with a simplified real life example.

From my experience, generators are not the most commonly used tool within Javascript. They tend to look complex and scare some developers. But they can actually be a huge improvement for your code!

If you really know generators, it’s either because you are using them with Redux Saga, because your company made the (great) choice of using them, or because you are someone curious! For me, it’s the third option.

But what really are generators

A generator is a function declared a bit differently compared to a normal function. The prototype of a generator is the following:

function* myGenerator(){}

This little star makes the whole difference. That and a specific keyword: yield.

#loading #generator #react #javascript

Javascript Generators with A Concrete Example
1.40 GEEK