I am using Yup for form data validation along with Formik.
This is a yup schema for one of my react forms.
const values=['All','Subscribers']
export const newsLetterSchema = yup.object().shape({
audience: yup.string(),
subject: yup.string().min(1).required("Required"),
body: yup.string().min(1).max(1000).required("Required"),
});
By this schema i want the "audience" field to have a value which is already pre-defined in the array of values by me and any other value should throw me an error.
The audience field should be either audience='All' or audience ='Subscribers' and if audience='any other value' then it should give me error. I tried to find a solution but could not find any. Thank you in advance.