<?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: saurav RT</title>
    <description>The latest articles on DEV Community by saurav RT (@saurav181229).</description>
    <link>https://dev.to/saurav181229</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%2F462676%2Fa0907b3f-f1c8-412c-8a0e-ad8565af8933.jpg</url>
      <title>DEV Community: saurav RT</title>
      <link>https://dev.to/saurav181229</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saurav181229"/>
    <language>en</language>
    <item>
      <title>React UseEffect() Rendering twice!</title>
      <dc:creator>saurav RT</dc:creator>
      <pubDate>Mon, 25 Sep 2023 16:37:21 +0000</pubDate>
      <link>https://dev.to/saurav181229/react-useeffect-rendering-twice-3ama</link>
      <guid>https://dev.to/saurav181229/react-useeffect-rendering-twice-3ama</guid>
      <description>&lt;p&gt;One of the strange behaviours I came across using useEffect().&lt;br&gt;
let's go through the effect and then jump into the solution.&lt;br&gt;
Here is a code below.&lt;/p&gt;

&lt;p&gt;App.js&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'
import { useEffect,useState } from 'react';
import './App.css';
import io from 'socket.io-client'

function App() {


  useEffect(()=&amp;gt;{
   console.log("hello from use effect");
  },[])

  return (
    &amp;lt;div&amp;gt;
  Hello world

    &amp;lt;/div&amp;gt;

  );
}

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

&lt;/div&gt;



&lt;p&gt;and index .js&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';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';


const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  &amp;lt;React.StrictMode&amp;gt;
    &amp;lt;App /&amp;gt;
  &amp;lt;/React.StrictMode&amp;gt;
);



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

&lt;/div&gt;



&lt;p&gt;This is a small code snippet where we are just showing "hello World" on the web page and there is a useeffect hook which prints&lt;br&gt;
"hello from use effect". After running it on the development server you can see the print statement printing twice in the console. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Mqy7PPKl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffzy1j8bdff538zgt5uw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Mqy7PPKl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffzy1j8bdff538zgt5uw.png" alt="Image description" width="800" height="93"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The solution is to remove the React.strictMode&lt;br&gt;
 tag around the app. and this solves our multiple render issues associated with useEffect.&lt;/p&gt;

&lt;p&gt;Thank you:)&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to pass parameters from child commponent to parent component in React?</title>
      <dc:creator>saurav RT</dc:creator>
      <pubDate>Mon, 14 Aug 2023 17:15:43 +0000</pubDate>
      <link>https://dev.to/saurav181229/how-to-pass-parameters-from-child-commponent-to-parent-component-in-react-9im</link>
      <guid>https://dev.to/saurav181229/how-to-pass-parameters-from-child-commponent-to-parent-component-in-react-9im</guid>
      <description>&lt;p&gt;Lets say we have a parent component App&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";
import { useState, useEffect } from "react";
import Search from "./Search";


const App = () =&amp;gt; {
  const [SearchData, SetSearchData] = useState("Enter text");

  const ReceiveText = (txt) =&amp;gt; {
    console.log(txt);
    SetSearchData(txt);
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Search HandleSearch={ReceiveText} /&amp;gt;
      &amp;lt;h1&amp;gt; {SearchData}&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;and we have a child component Search&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const Search = ({ HandleSearch }) =&amp;gt; {
  return (
    &amp;lt;div classs="search"&amp;gt;
      &amp;lt;label&amp;gt;Search &amp;lt;/label&amp;gt;
      &amp;lt;input
        placeholder="Search for movies"
        onChange={(e) =&amp;gt; HandleSearch(e.target.value)}

      /&amp;gt;
      &amp;lt;br&amp;gt;&amp;lt;/br&amp;gt;
      &amp;lt;button&amp;gt;Search&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Search;

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

&lt;/div&gt;



&lt;p&gt;App.js is a simple react component which has a child component Search.js.  In app.js I have created a method which take an arguement text and print the text that we will be passing from child. also I have declared a usestate hook searchdata which would have initial text 'enter text' and also we will be setting the state based on the input from child.&lt;br&gt;
In search.js file we are grabbing the method that is passed  from App.js.Also it has a simple input tag from where we can input our text.  it has an event handler onchange inside which iam calling handlesearch method which would get the text that we are entering from the input element and this text will be passed on to the handlesearch method of the parent component(App.js). As a result Searchdata would be updated which is in the App.js.&lt;br&gt;
And that is how you can pass property from child to parent.&lt;br&gt;
Thank you&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
    </item>
  </channel>
</rss>
