Recoil prevent UI blocking

andonmitev

Andon Mitev

Posted on September 27, 2022

Recoil prevent UI blocking

I'm using recoil and I have a heavy/time consuming operation which blocks the UI until it is done. In redux, we use saga for side effects to prevent UI blocking. How this can be achieved here?

Currently, I have this state:

export const clientsState = atom({
  key: 'clients',

  default: {},
  effects: [
    ({ setSelf, onSet }) => {
      onSet((seed) => {
        for (let i = 0; i < 100; i++) {
          console.log(i);
          // Time consuming operation
          const clients = createClients(seed as string);

          setSelf(clients);
        }
      });
    },
  ],
});
Enter fullscreen mode Exit fullscreen mode

and it takes a good amount of time to complete and unblock the UI.

💖 💪 🙅 🚩
andonmitev
Andon Mitev

Posted on September 27, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related