0

I want to map over values and return an instance of my <FirstRepeatAttributeLabelAssistant /> for every label (basically to render an label above each input, number of inputs can vary).

I've started off with this:

{object.attributeCollection.questions.map((question) => (
   <FirstRepeatAttributeLabelAssistant />
))}

The output of the map above is like so:

[StringAttributeModel, MemoAttributeModel, LabelAttributeModel, MemoAttributeModel, StringAttributeModel, StringAttributeModel] I only care about the "StringAttributeModel" as each of those 3 include 3 different labels (the part I care about). Their structure is like so:

enter image description here

How can I update my logic to ensure all of the potential labels are covered and a <FirstRepeatAttributeLabelAssistant /> component is rendered for each of them?

2
  • What are the required props of FirstRepeatAttributeLabelAssistant? And what did you show in your console? Was it object.attributeCollection.questions? Commented Sep 10, 2021 at 12:45
  • it's probably just going to take a prop of: question={question}. The log of that question in the child component is all of the different objects yeah object.attributeCollection.questions was what was shown in the console. Commented Sep 10, 2021 at 12:49

1 Answer 1

1

Suppose all your elements are a component, then you can simply do.

{object.attributeCollection.questions.map(Comp => {
  ...
  return <Comp label="..." />
})}

You can fill whatever your custom logic in the ... area.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.