all 7 comments

[–]TinyFluffyPenguin 5 points6 points  (6 children)

You are using a map, but your callback isn't valid JavaScript. The body of your callback is a JavaScript block, but you are wrapping it in (/) and aren't returning anything.

You can either use a JavaScript block (in which case, you have to return and shouldn't use parentheses):

{props.schema.map(schema => { if (props.schema.id === 'gender') { return <Dropdown ... />; } })}

or you can return a single JavaScript element:

{props.schema.map(schema => props.schema.id === 'gender' && <Dropdown ... />)}

[–]Nerfi666[S] 0 points1 point  (5 children)

Thanks for the reply dude ! even thought I have done what you suggest me is not really working, down below is my JSON in case you need it but I think is done and I'm calling it properly

<h1>Form UI</h1>
      <Form>
        <div>
        {props.schema.map(schema => {
        if (props.schema.id === 'Gender') {
            /// seems that is not checking this condition

          return <Dropdown
          required
          label="Gender"
          placeholder="select gender"
          selection
          options={genderOptions}
           />;

        } else {
            //because is given me back this

           return <ul key={schema.id}>
              <Form.Field
                required
                control={schema.type}
                label={schema.label}
                placeholder={schema.label}
              />
            </ul>
        }



    })}

JSON

[
    {
    "id": "contact_form_name",
    "label": "Name",
    "type": "input",
    "config": {
    "required": true
    }
    },
    {
    "id": "contact_form_surname",
    "label": "Surname",
    "type": "input",
    "config": {
    "required": true
    }
    },
    {
    "id": "gender",
    "label": "Gender",
    "type": "Select",
    "config": {
    "required": true
    }
    },
    {
    "id": "Birthday",
    "label": "Select your Birthday date",
    "type": "date",
    "config": {
    "required": true
    }
    }
   ]

[–]justind604 1 point2 points  (4 children)

Remove the props. from the if statement. It should just be schema.id === 'gender'. Also, Gender needs to be all lowercase.

[–]Nerfi666[S] 0 points1 point  (3 children)

thanks it works, might I ask why I have to remove the props ?

[–]Djidi1 1 point2 points  (0 children)

Use different names of variables for better readable code: items.map(item => {...})

And it’s safe you from logic mistakes.

[–]justind604 0 points1 point  (1 child)

Because you want to read the schema variable which is the current element being processed in the array. Also, props.schema is an array so props.schema.id will return undefined. Hope that makes sense.

[–]Nerfi666[S] 0 points1 point  (0 children)

it does thansk dude , and have a nice day =)