I'm working with a field that should have a value that matches a value from an enum. However, TypeScript complains when I try to set the field value to state due to the incompatibility between the field value (a string) and the enum.
Here's an example of what I'm trying to do:
import * as React from "react";
enum ValidValues {
foo = "foo",
bar = "bar"
}
export default function App() {
const [fieldValue, setFieldValue] = React.useState(ValidValues.foo);
return (
<input
value={fieldValue}
onChange={(e) => setFieldValue(e.currentTarget.value)}
/>
);
}
I understand why I get the Argument of type 'string' is not assignable to parameter of type 'SetStateAction<ValidValues>'
error, but I'm unsure how to make these compatible, if it is possible.