My journey with Typescript is relatively new, and I've recently built a snackbar component using React Context. However, when attempting to set the Alert severity, I encountered this error: "Type 'string' is not assignable to type 'Color | undefined'." Even though I have specified the type as string, I'm struggling to assign it a type of Color. Below is my Alert component code:
const AppAlert = () => {
const alertContext = useContext(AlertContext);
return (
<div>
<Snackbar open={alertContext.snackbarOpen}>
<Alert severity={alertContext.snackbarType} variant="filled">
{alertContext.snackbarMessage}
</Alert>
</Snackbar>
</div>
);
};
export default AppAlert;
Take a look at my Alert prop types below:
interface AlertProps {
snackbarOpen: boolean;
snackbarType: string;
snackbarMessage: string;
setAlert: (type: string, message: string) => void;
}
I hope my explanation was clear enough. I am still on the path to understanding TypeScript.