I want to use ENUM but I got this error message:
Argument of type '"MALE"' is not assignable to parameter of type 'Gender | (() => Gender | null) | null
Code:
enum Gender {
MALE = 'MALE',
FEMALE = 'FEMALE',
};
const [gender, SetGender] = useState<Gender | null>('MALE');```
CodePudding user response:
It is an enum
, so instead of using string 'MALE'
, use Gender
to reference the enum variable.
enum Gender {
MALE = 'MALE',
FEMALE = 'FEMALE',
};
const [gender, SetGender] = useState<Gender | null>(Gender.MALE); // valid code