Wednesday, October 31, 2018

Iterating/Loop Through Your Component Property in Render Function in React

Introduction

I understand that you need to build some UI elements dynamically in your component’s render function in React. Yes! The only way is to loop through the items; you can either use a for loop or a map function to do so. But the real question is, are we allowed to do that in React? Unfortunately, not in a direct way, you may face some difficulty, especially if you come from an Angular background. You were probably getting an error as like "unused expression, expected an assignment or function call," and now you are here on this page for an easy solution. It isn’t that hard to achieve, I will explain how. I hope you will like it.

Background

I have an array of addresses and I need to show this in a print template, so I thought about creating a separate component which iterates through the item property. And each array element has its own property and I wanted to generate labels for each item. Here I am going to explain how I did it.



from DZone.com Feed https://ift.tt/2CRuiQx

No comments:

Post a Comment