useRemap
Combine, map & mutate a new state from multiple sources.
function useMyHook() {
// ... some prelude
return (
useRemap<InstaLobbyResponse, InstaLobby>(instaLobbyResponse, {
initialValue: {
ready: false,
games: [],
floors: [],
},
mapper: InstaMapper,
mutate: useCallback((draft) => {
draft.games.forEach((game) => {
game.isFavorite = !!instaFavorites.favorites?.find(
gameRef => gameRef === game.ref
);
});
draft.ready = true;
}, [instaFavorites]),
})
)
}