How to create yup schema for dynamic array of different objects

13 views Asked by At

How to create yup schema for array of objects of different type. E.g. if I receive from backend questionnaire json where questions can be text input, choice, or numeric input. Every question object has unique id and type:

{
   "questionnaire":{
      "name":"set name",
      "description":"description",
      "questions":[
         {
            "id":"TextQuestion1",
            "text":"First Name",
            "type": "text",
            "answer":""
         },
         {
            "id":"MultilineQuestion1",
            "text":"Last Name",
            "type": "multiline",
            "answer":""
         },
         {
            "id":"NumericQuestion3",
            "type": "number",
            "text":"your Age",
            "NumValue":5
         },
         {
            "id":"ChoiceQuestion4",
            "type": "choice",
            "availableColours":[
               "red",
               "green",
               "blue"
            ],
            "favColours":"green"
         }
      ]
   }
}
0

There are 0 answers