0

I'm creating elements in React through arrays.

childArray.push(
    <span className={value}>
    </span>
)

...

parentArray.push(
      <Element>
          {({ value }) => (
              {childArray}
          )}
      </Element>
)

I want the child array to be able to access the parent prop value.

I'm using react-final-form with the FormSpy, which is when I ran into this issue. I can't change much about the situation I'm in.

1 Answer 1

2

Don't know how final-form might impact your code from what you share but using a function should fix your problem.

Depending on where it's declared you might need to pass childArray as an argument as well but otherwise:

function renderChildArray(value) {
  return childArray.push(
     <span className={value}>
      </span>
  )
} 

...

parentArray.push(
      <Element>
          {({ value }) => renderChidArray(value))} 
      </Element>
)
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.