<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anand Tangri on Medium]]></title>
        <description><![CDATA[Stories by Anand Tangri on Medium]]></description>
        <link>https://medium.com/@tangrianand?source=rss-bed5f6beb01b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*N5YDTniLuRPXtnx7.jpg</url>
            <title>Stories by Anand Tangri on Medium</title>
            <link>https://medium.com/@tangrianand?source=rss-bed5f6beb01b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 09:57:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tangrianand/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding one-way data binding in React]]></title>
            <link>https://medium.com/@tangrianand/understanding-one-way-data-binding-in-react-77fdb13db312?source=rss-bed5f6beb01b------2</link>
            <guid isPermaLink="false">https://medium.com/p/77fdb13db312</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Anand Tangri]]></dc:creator>
            <pubDate>Sun, 20 Sep 2020 17:37:27 GMT</pubDate>
            <atom:updated>2020-09-20T17:42:20.138Z</atom:updated>
            <content:encoded><![CDATA[<p>React is an open-source JavaScript library for building user interfaces or UI components. It is widely used to design simple views for each state in the application, and efficiently update and render just the right components when the data changes. React supports one-way data binding which means a unidirectional data-flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6q0vL2_jNNNiZK-9" /><figcaption>Photo by <a href="https://unsplash.com/@fifernando?utm_source=medium&amp;utm_medium=referral">Fidel Fernando</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is a unidirectional data-flow ?</h3><p>Unidirectional data-flow means that data has one, and only one, way to be transferred to other parts of the application. In React this means:</p><ol><li>State is passed to the view and child components</li><li>Actions are triggered from view and in turn update the state</li></ol><p>Let’s take a simple example of an input field in React:</p><pre>import React, { Component } from &#39;react&#39;;</pre><pre>class App extends Component {<br> state = {<br>   input_value: &#39;&#39;,<br> };</pre><pre>render() {<br>   return &lt;input <br>           name=&quot;input_value&quot; <br>           value={this.state.input_value} <br>          /&gt;;<br> }<br>}</pre><p>In the above example, if we go to the view and type something in the input box we will not see anything being typed in the box. This is because there is no event handler attached to the input field and the state associated with it can’t be changed without an event handler.</p><pre>import React, { Component } from &#39;react&#39;;</pre><pre>class App extends Component {<br> state = {<br>   input_value: &#39;&#39;,<br> };</pre><pre> handleChange = (e) =&gt; {<br>   this.setState({<br>      [e.target.name]: e.target.value<br>   })<br> }</pre><pre> render() {<br>   return &lt;input<br>           name=&quot;input_value&quot;<br>           value={this.state.input_value} <br>           onChange={this.handleChange}<br>          /&gt;;<br> }<br>}</pre><p>Now if we type anything in the input box, we will see the value in the input box changing as we type. Let us understand how this works.</p><p>We now have an event handler (action) attached to the input field i.e <em>handleChange()</em>, which triggers the state change which in turn is responsible for the re-render and thus a change in value of the input field as we type. This is unidirectional data flow or one-way data binding. This is known as a <a href="https://reactjs.org/docs/forms.html#controlled-components"><em>controlled component</em></a> where data is handled by React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k9ZZUEwzKc9xpz3ql64-zg.png" /></figure><p>Whenever user updates the state, React re-renders and thus a change is visible in the input box. Hopefully this example illustrates how one-way data binding works in React.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77fdb13db312" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>