Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I have decided it by myself. It should be:

label={values.item_type ? "Text1" : "Text2"}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!