u-wave/web

Move towards hooks-based state management

Closed this issue · 1 comments

I started with this in https://github.com/u-wave/web/blob/dfb04c70d302182e83253bf6c1aac8e6e7a70630/src/stores/MediaSearchStore.js.

Hooks let us write very reactive stores—for example, that one will auto-cancel an ongoing search request if a new one is started, which is not easy to achieve with redux actions.

Instead of action functions and reducers, we can put functions that manipulate state directly on the context object. Instead of selectors, we can either eagerly compute cheap things, or also export a function.

This migration is complicated primarily by our current use of selectors, because some of them are very interdependent. The easiest thing to do is to migrate "edge" selectors first. I think the next candidates are:

  • roomHistory
  • addToPlaylist (maybe this does not need a store at all)
  • dialogs
  • chat?
  • waitlist?

Worth looking into a few other things before moving everything over actually. Maybe redux toolkit could do requests for us for example. Using React's builtin context rerendering is a bit inefficient still.