Skip to content

Commit

Permalink
fix: correctly construct context object
Browse files Browse the repository at this point in the history
  • Loading branch information
bamdadfr committed Oct 9, 2024
1 parent 12c7a46 commit f81915a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/contexts/audio-url-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import React, {createContext, useContext, useMemo, useState} from 'react';

type AudioUrl = string | null;

type IContext = {
type Context = {
url: AudioUrl;
setUrl: React.Dispatch<React.SetStateAction<AudioUrl>>;
};

const AudioUrlContext = createContext<IContext>({} as IContext);
const AudioUrlContext = createContext<Context>({} as Context);

export function AudioUrlContextProvider({children}) {
const [url, setUrl] = useState<string | null>(null);
const memoizedUrl = useMemo(() => url, [url]);
const context = useMemo(() => ({url, setUrl}), [url, setUrl]);

return (
// eslint-disable-next-line react/jsx-no-constructed-context-values
<AudioUrlContext.Provider value={{url: memoizedUrl, setUrl}}>
<AudioUrlContext.Provider value={context}>
{children}
</AudioUrlContext.Provider>
);
Expand Down

0 comments on commit f81915a

Please sign in to comment.