0

trying to render component dinamically in a loop but it is giving me this error however directly sending the data in props working fine ongoingAssesements = assesmentData.filter((item) => item.assesmentStatus == "ongoing") newAssesements = assesmentData.filter((item) => item.assesmentStatus == "new") console.log(newAssesements) completedAssesements = assesmentData.filter((item) => item.assesmentStatus == "completed") below code is working fine

 <Assessments data={assesmentData[2]} />

but while looping it is giving error

{(completedAssesements && completedAssesements.length > 0) &&
            completedAssesements.map((item) =>
             <Assessments data={item} />
             
            )

 **error
Cannot read properties of undefined (reading 'setExtraStackFrame') **

1
  • What is setExtraStackFrame in your code? Commented Aug 1, 2022 at 12:25

1 Answer 1

1

Key is missing.

Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity - From React Docs https://reactjs.org/docs/lists-and-keys.html

{(completedAssesements && completedAssesements.length > 0) &&
            completedAssesements.map((index, item) =>
             <Assessments key={index} data={item} />
             
)}

You can refer to this issue: https://github.com/facebook/react/issues/20359

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

3 Comments

thank you, i am learning react this helped me a lot
Yes. It seems that now React 18 is throwing a TypeError: Cannot read properties of undefined (reading 'setExtraStackFrame') if you forget to add a key while looping through an array with map. The error used to be more descriptive, something like every prop needs a key in earlier versions of React
In map function It is probably: item, index

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.