<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>React Component Properties &#8211; Sibeesh Passion</title>
	<atom:link href="https://mail.sibeeshpassion.com/tag/react-component-properties/feed/" rel="self" type="application/rss+xml" />
	<link>https://mail.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Mon, 29 Oct 2018 17:33:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>React Component Properties &#8211; Sibeesh Passion</title>
	<link>https://mail.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Iterating/Loop Through Your Component Property in Render Function in React</title>
		<link>https://mail.sibeeshpassion.com/iterating-loop-through-your-component-property-in-render-function-in-react/</link>
					<comments>https://mail.sibeeshpassion.com/iterating-loop-through-your-component-property-in-render-function-in-react/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 29 Oct 2018 14:28:32 +0000</pubDate>
				<category><![CDATA[React]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[React Component]]></category>
		<category><![CDATA[React Component Properties]]></category>
		<category><![CDATA[React Render Function and Loop]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13314</guid>

					<description><![CDATA[[toc] Introduction I understand that you need to build some UI elements dynamically in your component&#8217;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 &#8221; unused expression, expected an assignment or function call&#8221;, and now you are here in this page [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>I understand that you need to build some UI elements dynamically in your component&#8217;s render function in <a href="https://sibeeshpassion.com/category/react/">React</a>. 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 &#8221; unused expression, expected an assignment or function call&#8221;, and now you are here in this page for an easy solution. It isn&#8217;t that hard to achieve, I will explain how. I hope you will like it.</p>
<h2>Background</h2>
<p>I have an array of addresses and I need to show this in a print template, so I thought of 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.</p>
<h2>Let&#8217;s start coding</h2>
<p>The first thing is, I have an interface for the address list properties as below.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">import { IAddressData } from "../../../interfaces/IAddressData";
export interface IAddressListProps {
    items: IAddressData[];
}</pre>
<p>Now I have created a component called PrintAddressList.tsx and written some code.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">import * as React from "react";
import { IAddressListProps } from '../../detailPage/components/interfaces/IAddressListProps';

export class PrintAddressList extends React.Component&lt;IAddressListProps, {}&gt;{
  constructor(props: IAddressListProps) {
    super(props);
  }

  public render(): React.ReactElement&lt;IAddressListProps&gt; {
    return (
      &lt;div&gt;
      &lt;/div&gt;
    );
  }
}</pre>
<p>And I need to have my custom labels for each address inside the div element in the render function. To do so, I had created a private function called createAddressCard which will loop through my props and return the HTML I need.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">private createAddressCard = () =&gt; {
    let parent = [];
    this.props.items.map((address) =&gt; {
      parent.push(&lt;div style={{ padding: '10px', border: '1px solid #ccc', margin: '5px' }}&gt;
        &lt;label&gt;{config.colNames.addressList.clmnAddressType}: &lt;/label&gt;
        &lt;label&gt;{address.Adressart}&lt;/label&gt;&lt;br /&gt;
        &lt;label&gt;{config.colNames.addressList.clmnCompanyName}: &lt;/label&gt;
        &lt;label&gt;{address.Firma}&lt;/label&gt;&lt;br /&gt;
        &lt;label&gt;{config.colNames.addressList.clmnPlaceName}: &lt;/label&gt;
        &lt;label&gt;{address.Ort}&lt;/label&gt;&lt;br /&gt;
        &lt;label&gt;{config.colNames.addressList.clmnZipCode}: &lt;/label&gt;
        &lt;label&gt;{address.PLZ}&lt;/label&gt;&lt;br /&gt;
        &lt;label&gt;{config.colNames.addressList.clmnTelephone}: &lt;/label&gt;
        &lt;label&gt;{address.Telefon}&lt;/label&gt;&lt;br /&gt;
      &lt;/div&gt;);
    });
    return parent;
  }</pre>
<p>Now I can easily call this function inside the render function.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">public render(): React.ReactElement&lt;IAddressListProps&gt; {
    return (
      &lt;div&gt;
        {this.createAddressCard()}
      &lt;/div&gt;
    );
  }</pre>
<p>Below is the complete code for the component.</p>
<p><a href="https://gist.github.com/SibeeshVenu/d2e11ed225a0568ded27c6f8fec0956c">https://gist.github.com/SibeeshVenu/d2e11ed225a0568ded27c6f8fec0956c</a></p>
<h2><span id="conclusion_1"><span id="conclusion">Conclusion</span></span></h2>
<p>In this post, we have learned how we can iterate our components properties inside a render function in the React component, for creating custom elements dynamically.</p>
<h2><span id="your-turn-what-do-you-think">Your turn. What do you think?</span></h2>
<p>Thanks a lot for reading. Did I miss anything that you may think which is needed? Could you find this post as useful? If yes, please like/share/clap for me. Thanks in advance.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mail.sibeeshpassion.com/iterating-loop-through-your-component-property-in-render-function-in-react/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
