rallly/components/user-name-context.tsx
2022-04-12 07:14:28 +01:00

12 lines
345 B
TypeScript

import React from "react";
export const UserNameContext =
React.createContext<[string, (userName: string) => void] | null>(null);
export const useUserName = () => {
const contextValue = React.useContext(UserNameContext);
if (contextValue === null) {
throw new Error("Missing UserNameContext.Provider");
}
return contextValue;
};