'Changing label at the Formik switcher

I created switcher with Formik. The switcher label should change as well. It works for now, but only with boolean value.

enter image description here

However, I need not boolean at the label but string. For example, instead of "true/false" a need to show "Text1/Text2".

Here is my code:

 const createItemTypeInitState = {
              item_type: false, // this boolean values works properly, switching the label text between true/false
              item_type_name: "Text1", // here should be the string values "Text1"/"Text2", depending on the switcher on/off
    };

  const [initialValues, setInitialValues] = useState<createItemData>(
    createItemTypeInitState
  );
            
        <FormControl component="fieldset" variant="standard">
            <FormGroup>
                 <FormControlLabel
                    control={
                       <Android12Switch
                           checked={values.item_type}
                           onChange={handleChange}
                           name="item_type"
                        />
                     }
                     label={`${values.item_type}`}
                 />
            </FormGroup>
        </FormControl>

So I need to change boolean value item_type to the string value item_type_name. Please help me do it.



Solution 1:[1]

I have decided it by myself. It should be:

label={values.item_type ? "Text1" : "Text2"}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yulia