by AlexErrant · 1w ago · 0 comments
That does not work because `loadTTS` is actually a hook, so its `useLoadTTS`, and hooks must be top level. I encourage you to look at the pastebin in my link, repeated here https://pastebin.com/sjc3vXTd
So, I must have
let provider = useGetUserPreference()
let a = useLoadTTS_A()
let b = useLoadTTS_B()
let c = useLoadTTS_C()
useEffect(() => {
if (provider=="a") a()
if (provider=="b") b()
if (provider=="c") c()
})
Oh hey, what's that? I have to allocate memory for b and c even though only a is used? THANKS REACT. const players = {
sherpa: SherpaPlayer,
local: LocalPlayer,
gemini: GeminiPlayer,
} satisfies Record<VoiceProvider, React.ComponentType>;
function PlayerSwitcher() {
const provider = useAppStore.use.voiceProvider();
const Player = players[provider];
return <Player />;
}
function useRegisterPlayer(player: Player, shortPlayer: Player) {
const { setPlayer, setShortPlayer } = useAppActions();
useEffect(() => {
setPlayer(player);
setShortPlayer(shortPlayer);
}, [player, shortPlayer, setPlayer, setShortPlayer]);
}
function LocalPlayer() {
useRegisterPlayer(useLocalPlayer(), useShortLocalPlayer());
return null;
}
function GeminiPlayer() {
useRegisterPlayer(useGeminiPlayer(), useShortGeminiPlayer());
return null;
}
function SherpaPlayer() {
useRegisterPlayer(useSherpaPlayer(), useShortSherpaPlayer());
return null;
}Trust me, I hate hooks. I don't use them unless I must.