<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thilina Dinelka</title>
    <description>The latest articles on DEV Community by Thilina Dinelka (@dinelkathilina).</description>
    <link>https://dev.to/dinelkathilina</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1540540%2F08e3d745-eb73-428b-bddd-6339148df8d5.jpg</url>
      <title>DEV Community: Thilina Dinelka</title>
      <link>https://dev.to/dinelkathilina</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dinelkathilina"/>
    <language>en</language>
    <item>
      <title>How to Pass Data Between Components in React</title>
      <dc:creator>Thilina Dinelka</dc:creator>
      <pubDate>Tue, 28 May 2024 18:36:02 +0000</pubDate>
      <link>https://dev.to/dinelkathilina/how-to-pass-data-between-components-in-react-edb</link>
      <guid>https://dev.to/dinelkathilina/how-to-pass-data-between-components-in-react-edb</guid>
      <description>&lt;p&gt;in React, passing data between components is a common task. You often need to share data from a Parent component to child component using props (short for "properties").&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Props?
&lt;/h2&gt;

&lt;p&gt;you can think of props as arguments that you send to a function, but in this case  sending them to a component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: Passing data from Parent to Child
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;Create Parent Component&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ChildComponent from './ChildComponent';

function ParentComponent() {
  const message = "Hello from the Parent Component!";

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;This is the Parent Component&amp;lt;/h1&amp;gt;
      &amp;lt;ChildComponent message={message} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default ParentComponent;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.&lt;code&gt;Create Child Component&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

function ChildComponent(props) {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h2&amp;gt;This is the Child Component&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;{props.message}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default ChildComponent;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>tutorial</category>
      <category>react</category>
      <category>programming</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
