v3: code quality pass, various bug fixes
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { useState } from "react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { PlayerContext, type PlayerItem } from "./PlayerContext.ts";
|
||||
|
||||
export function PlayerProvider({ children }: { children: React.ReactNode }) {
|
||||
const [current, setCurrent] = useState<PlayerItem | null>(null);
|
||||
|
||||
const play = setCurrent;
|
||||
const stop = useCallback(() => setCurrent(null), []);
|
||||
const value = useMemo(() => ({ current, play, stop }), [current, play, stop]);
|
||||
|
||||
return (
|
||||
<PlayerContext.Provider
|
||||
value={{ current, play: setCurrent, stop: () => setCurrent(null) }}
|
||||
>
|
||||
<PlayerContext.Provider value={value}>
|
||||
{children}
|
||||
</PlayerContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user