<?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 Bulbul Ahmed on Medium]]></title>
        <description><![CDATA[Stories by Bulbul Ahmed on Medium]]></description>
        <link>https://medium.com/@mr.bulbul.rbl?source=rss-d813da2265f8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*yca6vUfBeB6NwIZGeaR8SQ.jpeg</url>
            <title>Stories by Bulbul Ahmed on Medium</title>
            <link>https://medium.com/@mr.bulbul.rbl?source=rss-d813da2265f8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 07:55:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mr.bulbul.rbl/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[Understand the react hook ‘useEffect’ : In a Simplest Way]]></title>
            <link>https://medium.com/react-hooks/understand-the-react-hook-useeffect-in-a-simplest-way-962216efa928?source=rss-d813da2265f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/962216efa928</guid>
            <dc:creator><![CDATA[Bulbul Ahmed]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 20:39:10 GMT</pubDate>
            <atom:updated>2020-04-13T20:39:10.449Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understand the react hook ‘useEffect’ : In a Simplest Way</h3><p>Today we gonna learn about the trickiest react hook ‘useEffect’. It is very useful to control the side effects of your react component, basically along with useState hook. If you haven’t any knowledge of ‘useState’ hook, I will recommend you to have some knowledge of this hook first by searching on google.</p><p>There are some methods called ‘component life cycle’ in react which may create little complicacy in our discussion. As I promised to describe the topic in a simplest way, I gonna avoid that ‘component life cycle’ method intentionally. Alright, let’s have a deep dive into the react hook ‘useEffect’ with some operational demonstration -</p><p>Create a react app using ‘create-react-app’ command and write the following codes in “App.js” and “App.css” respectively-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0WV6d6LFWrSRGX732dR01w.png" /><figcaption>Get the code from here: <a href="https://drive.google.com/open?id=1cf3icCvHULtn10F1I2cVHEi5zB78szI9">https://drive.google.com/open?id=1cf3icCvHULtn10F1I2cVHEi5zB78szI9</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BemTSEmxq07UC0Jv2owYiQ.png" /></figure><p>Important: Unlike useState, useEffect has the complete different signature. In our ‘App.js’ file ‘cart’ is the name of a constant/variable which returns some values and ‘setCart’ is the function used set a value to that constant/variable. Meanwhile for ‘useEffect’ is a function which accepts a callback function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*0zw_w5CsZFICv3Lrnt4HQg.png" /><figcaption>Here is our output, it showing value of the state ‘cart’ is zero and a console log ‘useEffect initialized’. Remember our ‘useEffect’ rendered once when the page is loaded.</figcaption></figure><p>Interesting thing about ‘useEffect’ that, you can use it as much as times you want.</p><p>Change your code as follows -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bnGHlNj4LKZNzknILoaDpw.png" /><figcaption>Get the code from here: <a href="https://drive.google.com/open?id=1CvN2-4jaEUgPB1EYR8n82vTe-p1GTpVy">https://drive.google.com/open?id=1CvN2-4jaEUgPB1EYR8n82vTe-p1GTpVy</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*ZKgFkgyiNR7Q0mEAoHhdgA.png" /><figcaption>Your output will be like this</figcaption></figure><p>Look, there is two console log from two ‘useEffect’s, the first one rendered when page is loaded and the second one will render with every update of the page (i.e. once when page is loaded and each times you click ‘add to cart’ button). The first one is rendered one because of the empty array at the end of the useEffect function.</p><p>You can write some functions inside you useEffec function including a return function like that -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qa2V4LJe4GBpYai6mdhqIQ.png" /><figcaption>Get the code from here: <a href="https://drive.google.com/open?id=17S9SPPsawhLC4aGXpxVLPhuwLKO_pfaG">https://drive.google.com/open?id=17S9SPPsawhLC4aGXpxVLPhuwLKO_pfaG</a></figcaption></figure><p>The output of this code is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*5UgSfeips7VVolRzcUojlw.png" /><figcaption>After adding 6 items in our cart the document title will be changed and a return function will be called (in this case, “you need to cleanup your card” in the console).</figcaption></figure><p>Now, we will do something different with our useEffect hook. We gonna retrieve data from fake REST API named “JSONPlaceholder”and showing it in our web page. To do this we will create a new component named ‘FetchData.js’ and write the following code into it-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s4DQv2GtpA0okrKsmmHytQ.png" /><figcaption>Get the code from here: <a href="https://drive.google.com/open?id=1s0Gs-pTs1MSdhcs-kJWQBZgdX6Yp21NO">https://drive.google.com/open?id=1s0Gs-pTs1MSdhcs-kJWQBZgdX6Yp21NO</a></figcaption></figure><p>Import the component to your ‘App.js’ and write the following code-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1T4-T-EfdfrW7ELTlKLfqg.png" /><figcaption>Get the code from here: <a href="https://drive.google.com/open?id=1nJ_vu9w-YYK5JDbGWRQ3ep2mdazuCbth">https://drive.google.com/open?id=1nJ_vu9w-YYK5JDbGWRQ3ep2mdazuCbth</a></figcaption></figure><p>Now you have retrieved data from a fake REST API and output will be as follows-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*5wyh8tWjqv0hHyEIBo3lAQ.png" /><figcaption>It showing the title of each posts</figcaption></figure><p>That’s all from me for today, here I tried to show you the different use of the react hook useEffect. Thanks for being with me, see you in my next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=962216efa928" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-hooks/understand-the-react-hook-useeffect-in-a-simplest-way-962216efa928">Understand the react hook ‘useEffect’ : In a Simplest Way</a> was originally published in <a href="https://medium.com/react-hooks">React Hooks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Context API in React: In Simplest Way]]></title>
            <link>https://medium.com/react-hooks/context-api-in-react-in-simplest-way-139d94a7b2d9?source=rss-d813da2265f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/139d94a7b2d9</guid>
            <category><![CDATA[user-management]]></category>
            <category><![CDATA[usememo]]></category>
            <category><![CDATA[usecontext]]></category>
            <category><![CDATA[context-api]]></category>
            <category><![CDATA[react-context-api]]></category>
            <dc:creator><![CDATA[Bulbul Ahmed]]></dc:creator>
            <pubDate>Fri, 10 Apr 2020 21:17:46 GMT</pubDate>
            <atom:updated>2020-04-10T21:17:46.145Z</atom:updated>
            <content:encoded><![CDATA[<p>By the end of this article, you are going to learn-</p><p>· How you can pass values trough out your react components using Context API.</p><p>· User login management in your react app.</p><p>Alright! the advantage of context API is, we can access the value of something in the app from any component, no matter where the position of the value in the component tree. we gonna use VS code to do this. So, let’s jump into it-</p><p>To make the demonstration very easy I have explained in 4 separate sections.</p><p>Section1: Pass a simple message using useContext: We have to prepare a simple react app for this-</p><p>a. Create react app using ‘create-react-app’ command</p><p>b. Install react router using ‘install react-router-dom.</p><p>c. After installation done go to ‘App.js’ file and type following codes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*lqRuIu7H9VLO2ZkQlIqdyQ.png" /><figcaption>Get the code from: <a href="https://drive.google.com/open?id=1TgLQqwEgxe7zcQlC4ukeT5HJprYOJKLw">https://drive.google.com/open?id=1TgLQqwEgxe7zcQlC4ukeT5HJprYOJKLw</a></figcaption></figure><p>d. Delete all the css codes of ‘App.css’ and write only as follows-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WARtV23PlJxhLZonAWTZbw.png" /></figure><p>e. Inside the ‘src’ folder create a new folder named ‘components’ and make three files named ‘Home.js’, ‘ContactUs.js’ &amp; ‘UseContext.js’.</p><p>f. Open ‘ContactUs.js’ and write codes like that -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0aUGOhVR-j3m9KUIR57BCA.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1zrBov_BFai-DyLIGrnLQhs37iR3GCuY3">https://drive.google.com/open?id=1zrBov_BFai-DyLIGrnLQhs37iR3GCuY3</a></figcaption></figure><p>g. The code of ‘Home.js’ will be -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gLSK6lG4urvaoKgWwGRzVw.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1gIQQRrP0D5ySkqm_dRfVBdpiVMjgHAmz">https://drive.google.com/open?id=1gIQQRrP0D5ySkqm_dRfVBdpiVMjgHAmz</a></figcaption></figure><p>h. Write the following codes in ‘UseContext.js’-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jd0zbElYmc9NMw7Z9mCrJA.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1BdH0pOVX9Rq2AFTrgWSrTYMw5IiU3V2u">https://drive.google.com/open?id=1BdH0pOVX9Rq2AFTrgWSrTYMw5IiU3V2u</a></figcaption></figure><p>i. Now open the live server using ‘npm start or yarn start’ command and the output will be as follows-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*24FKw2PlElIZEyaCyZX88w.png" /><figcaption>This is the home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*I-NY57L0Ajat4QCgDrgJpA.png" /><figcaption>If you click on Contact Us link you can see this</figcaption></figure><p>You already did the hardest part of this article now try to understand what you did in this section, you have passed a message dynamically though out the components using useContext hook.</p><p>Section 2: In this section we will set a new message as the value of our state.</p><p>As we know, there are two things in a state, one is state value and another is a function to set the value.</p><p>We are going to set a new value (new message in this case) using setMsg function-</p><p>a. Change the code of ‘App.js’ to -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w95CjW6xLphAXsjtsrLUMQ.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1feI87_rl7g3hjrGgvvr1Yypdl0hEsxrw">https://drive.google.com/open?id=1feI87_rl7g3hjrGgvvr1Yypdl0hEsxrw</a></figcaption></figure><p>b. Open ‘Home.js’ and change the code as follows-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FwRrrsi6YWVkQ_GSuaXD1Q.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1XDXClvk__2W-w67p9Vl-PDq1MqFw-uQt">https://drive.google.com/open?id=1XDXClvk__2W-w67p9Vl-PDq1MqFw-uQt</a></figcaption></figure><p>c. Change the code of ‘ContactUs.js’ -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-sRv9rCoWygWcidVBIWKg.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1pjV-c9bUP3Tjkj9WvUnFeKH2TI4sVMrF">https://drive.google.com/open?id=1pjV-c9bUP3Tjkj9WvUnFeKH2TI4sVMrF</a></figcaption></figure><p>All other things will remain the same. If you open the live server and go to home page, the output will be -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*aWy1VkJYP5AUK2WVBL2W6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*Usb5qCL9M_GF0kJBlt0CRQ.png" /><figcaption>If you click on ‘Set New Value’ button the text of dynamically passed message will be changed</figcaption></figure><p>In the same way, the output of ‘Contact Us’ page will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*JSRvkw30lj0xxzvaanT6DQ.png" /></figure><p>If you click on ‘Set New Value’ button, the output will be -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*kMruXbGLmesDkgVqxiFkqA.png" /><figcaption>You can access your newly set value from both of your components.</figcaption></figure><p>Section 3: In this section we are going to pass a complete object to all the child components. To do this, we have to change only the code of ‘App.js’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4xhIiMdPCAM9Gu3ZhktlKg.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1aObuCe53sZwam8wxz2MQs-VdhCXKT15m">https://drive.google.com/open?id=1aObuCe53sZwam8wxz2MQs-VdhCXKT15m</a></figcaption></figure><p>We have used useMemo hook to pass the object to our components and the output is not affected at all. This way we can pass a complete object using Context API.</p><p>Section 4: In this section we are going to share an user object among our components and it is very important section of this article because developers have to deal with user logins most often now a days.</p><p>a. Create a file in the component folder named ‘login.js’ and write this function into it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8488i33wFlMCjxXtafItOQ.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=15UMbKFIxDN7ZSPHVIDyusnzLIUxgAT3i">https://drive.google.com/open?id=15UMbKFIxDN7ZSPHVIDyusnzLIUxgAT3i</a></figcaption></figure><p>This is an synchronous function which returns an user ID, username and email.</p><p>b. Go to ‘App.js’ and retouch the codes like that-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ePREBic2ZSCNAPc-PW8KpA.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1DdY7MLHhUnEFEb4X32CXs-acjGO7Flz7">https://drive.google.com/open?id=1DdY7MLHhUnEFEb4X32CXs-acjGO7Flz7</a></figcaption></figure><p>you are passing an user object to both of your components.</p><p>c. The codes of ‘Home.js’ will be-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fwRmR63PjfJM5iU_GnMTkg.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1UGsjEJmXoXsPryYpl-HDHhzxIxxEKieE">https://drive.google.com/open?id=1UGsjEJmXoXsPryYpl-HDHhzxIxxEKieE</a></figcaption></figure><p>d. Edit the code of ‘ContactUs.js’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nkdDKV9wFkvfrvWB8wTe2Q.png" /><figcaption>Get the code from : <a href="https://drive.google.com/open?id=1AUSFCOj35O9jpsAmplFLvJJrH83i3xc0">https://drive.google.com/open?id=1AUSFCOj35O9jpsAmplFLvJJrH83i3xc0</a></figcaption></figure><p>The ‘UserContext.js’ file will remain same as it was written first time. Now you can see the output in live server like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j52FqAIDDolpVaRijkpWNQ.png" /><figcaption>No user is logged in and it showing the login button</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrZf0zl3Xwi3VaciRAa7HQ.png" /><figcaption>After clicking the ‘Log In’ button the user will be logged in and it will show the ‘Log out’ button</figcaption></figure><p>If you go to the ‘Contact Us’ page it will show like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0D_3zb7AErZTxKYNkWNGQg.png" /><figcaption>The user also logged in for this component.</figcaption></figure><p>Again if you go to ‘Home’ page and click on ‘Log Out’ button, the user will be logged out and the value of the object will be ‘null’.</p><p>In this way, we have learned about Context API using userContext and now we can manage our user’s login in our web app.</p><p>Thank you for your patience, if you have any question about this article feel free to ask me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=139d94a7b2d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-hooks/context-api-in-react-in-simplest-way-139d94a7b2d9">Context API in React: In Simplest Way</a> was originally published in <a href="https://medium.com/react-hooks">React Hooks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>