<?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: thatFemicode</title>
    <description>The latest articles on DEV Community by thatFemicode (@thatfemicode).</description>
    <link>https://dev.to/thatfemicode</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%2F441157%2F7bc01b94-7be7-4b1d-8cbe-a995c094f3ad.jpg</url>
      <title>DEV Community: thatFemicode</title>
      <link>https://dev.to/thatfemicode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thatfemicode"/>
    <language>en</language>
    <item>
      <title>Pass Data from children Component to Parent Component in ReactJs</title>
      <dc:creator>thatFemicode</dc:creator>
      <pubDate>Mon, 08 Aug 2022 19:01:00 +0000</pubDate>
      <link>https://dev.to/thatfemicode/pass-data-from-children-component-to-parent-component-in-reactjs-559n</link>
      <guid>https://dev.to/thatfemicode/pass-data-from-children-component-to-parent-component-in-reactjs-559n</guid>
      <description>&lt;p&gt;Been studying for Frontend React interviews the past few weeks should I get one and came across a question from the guide I was using and honestly got confused because I know of passing data from Parent to child since React is unidirectional and when doing that Vice versa, passing data from child to parent you use either the Context API for or state management libraries like Redux, Mobx or Recoil, FYI I am only familiar with Redux but found an interesting answer to the question since the question said not to use either Context API or Redux or any state management library so after googling and the regular Stackoverflow, reading some medium articles and reading the React Docs a little I found out you can actually pass data from child to parent using CALLBACKS.&lt;/p&gt;

&lt;p&gt;I was confused at first then I remembered according to MDN docs:&lt;br&gt;
A callback function is a function passed into another function as an argument. This call back function is then invoked inside the outer function to complete some kind of routine or action.&lt;/p&gt;

&lt;h1&gt;
  
  
  Procedure
&lt;/h1&gt;

&lt;p&gt;There are basically two steps to achieve this process and I will be listing them and creating a component as we go&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating a Parent component and then creating a callback function in the parent component
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;ParentComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;team&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTeam&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;here&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt; &lt;span class="nx"&gt;will&lt;/span&gt; &lt;span class="nx"&gt;be&lt;/span&gt; &lt;span class="nx"&gt;passed&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;prop&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;childcomponent&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addTeam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;team&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setTeam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;team&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;Parent&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt; &lt;span class="nx"&gt;we&lt;/span&gt; 
        &lt;span class="nx"&gt;will&lt;/span&gt; &lt;span class="nx"&gt;be&lt;/span&gt; &lt;span class="nx"&gt;focusing&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Your&lt;/span&gt; &lt;span class="nx"&gt;selected&lt;/span&gt; &lt;span class="nx"&gt;team&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;team&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="nx"&gt;Below&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;addTeam&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;then&lt;/span&gt; &lt;span class="nx"&gt;passed&lt;/span&gt; &lt;span class="nx"&gt;into&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;prop&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="nx"&gt;addTeam&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;addTeam&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Creating structure of the ChildComponent
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ChildComponet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;addTeam&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;The&lt;/span&gt; &lt;span class="nx"&gt;addTeam&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;will&lt;/span&gt; &lt;span class="nx"&gt;then&lt;/span&gt; &lt;span class="nx"&gt;be&lt;/span&gt; &lt;span class="nx"&gt;used&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;push&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;team&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;selected&lt;/span&gt; &lt;span class="nx"&gt;back&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;ParentComponent&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;teams&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;LA Clippers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Boston Celtics&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cleveland Cavilers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Memphis Grizzlies&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Choose&lt;/span&gt; &lt;span class="nx"&gt;Your&lt;/span&gt; &lt;span class="nx"&gt;Team&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;child&lt;/span&gt; 
          &lt;span class="nx"&gt;component&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;teams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;team&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;addTeam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;team&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;})}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the ChildComponent we simply used an &lt;strong&gt;onClick&lt;/strong&gt; property to handle user click and then the data clicked is passed to the parent component and your selected team is displayed on your screen, the action is thereby complete. &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Data has successfully been passed from the ChildComponent to to the ParentComponent and the unidirectional flow of react is beaten. If you feel I made a mistake, kindly hit me to tell me what I missed, thanks for reading.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Passing Data (states) through React Router</title>
      <dc:creator>thatFemicode</dc:creator>
      <pubDate>Sun, 13 Mar 2022 17:31:06 +0000</pubDate>
      <link>https://dev.to/thatfemicode/passing-data-states-through-react-router-8dh</link>
      <guid>https://dev.to/thatfemicode/passing-data-states-through-react-router-8dh</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;I was working on a side project recently in React and i wanted to pass data(state) from a component (Page) that was not in my initial component to another component(page). This might sound confusing but let me explain, basically the component i wanted to pass this particular state to was not imported to my component because it was a stand alone page i.e. had a different route, this was giving me issues for about a day till i started going through the react router docs and found out that you can pass state with &lt;strong&gt;Link&lt;/strong&gt; component  and &lt;strong&gt;useNavigate hook&lt;/strong&gt; from react-router-dom routing package for react.&lt;br&gt;
This article shows you a elegant approach to passing data via the &lt;strong&gt;Link&lt;/strong&gt; component and &lt;strong&gt;useNavigate hook&lt;/strong&gt; and accessing the data passed with the &lt;strong&gt;useLocation hook&lt;/strong&gt; which is just a simple technique. I will display code using React functional components. Without further ado, let's get into it. &lt;/p&gt;
&lt;h1&gt;
  
  
  Passing Data
&lt;/h1&gt;

&lt;p&gt;Data known as state can be passes  via the Link component in the same way we pass props but it has a certain key (name) that has to be given to it in order for the data to be retrieved via the useLocation hook and also with the useNavigate hook also to be retrieved via the useLocation hook.&lt;/p&gt;

&lt;p&gt;I'll be explaining both methods and how they can be done.&lt;/p&gt;
&lt;h2&gt;
  
  
  Link
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Link } from 'react-router-dom';
const item = () =&amp;gt;{
//data to be passed
const Data = {
  name: 'Femi',
  phoneNumber: 123
}
&amp;lt;Link to="/some-where" state={myData}&amp;gt;Link Text&amp;lt;/Link&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;the above shows the Item (Route) component that we passed the data from, we will be retrieving the data below in Profile (Route) component.&lt;/p&gt;
&lt;h2&gt;
  
  
  useNavigate
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useNavigate } from 'react-router-dom';
const item = () =&amp;gt;{
  const nav = useNavigate();
//data to be passed
const Data = {
  name: 'Femi',
  phoneNumber: 123
}
&amp;lt;div onClick={() =&amp;gt; {
 nav("/some-where", { state:data});
}}&amp;gt;Clickme
&amp;lt;/div&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The below shows how data is retreived after it has been passed by the two methods above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useLocation } from 'react-router-dom';
const Profile = () =&amp;gt;{
const location = useLocation();
//the data here will be an object since an object was
const data = location.state;
console.log(data);
&amp;lt;p&amp;gt;data.name&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;data.phoneNumber&amp;lt;/p&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Illustrating the above in a simple project
&lt;/h1&gt;

&lt;p&gt;I'm guessing most of us can set up a react project with the traditional npx-create-react-app appname method, if you dont kindly check on how to do this from the react docs. &lt;/p&gt;

&lt;p&gt;I will be using just the &lt;strong&gt;Link&lt;/strong&gt; component to shocase this little build&lt;br&gt;
Three Major component here. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App.jsx&lt;/li&gt;
&lt;li&gt;Home.jsx&lt;/li&gt;
&lt;li&gt;Profile.jsx&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;//App.jsx&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 things from react-router-dom
import { BrowserRouter, Routes, Route } from "react-router-dom";

// import pages
import HomePage from "./Home";
import ProfilePage from "./Profile";
function App() {
  return (
&amp;lt;BrowserRouter&amp;gt;
  &amp;lt;div style={{padding: 30}}&amp;gt;
    &amp;lt;Routes&amp;gt;
 &amp;lt;Route path="/" element={&amp;lt;HomePage/&amp;gt;} /&amp;gt;&amp;lt;Route path="/about" element={&amp;lt;ProfilePage /&amp;gt;} /&amp;gt;
   &amp;lt;/Routes&amp;gt;
 /div&amp;gt;
 &amp;lt;/BrowserRouter&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;//Home.jsx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Link } from "react-router-dom";

const HomePage = () =&amp;gt; {
  // this is for the first Link
  const data1 = {
    from: "David",
    message: "Welcome to David.com",
    return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Home Page&amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;
        &amp;lt;Link to="/about" state={data1}&amp;gt;
          Go to Profile Page
        &amp;lt;/Link&amp;gt;
      &amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;//Profile.jsx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useLocation, Link } from "react-router-dom";

const Profile = () =&amp;gt; {
  const location = useLocation();
  const state = location.state;
  console.log(state);
  return (
    &amp;lt;&amp;gt;
&amp;lt;h1&amp;gt;Profile page&amp;lt;/h1&amp;gt;  
   &amp;lt;div&amp;gt;
      &amp;lt;h3&amp;gt;Passed data:&amp;lt;/h3&amp;gt;
       &amp;lt;p&amp;gt;From: {state.from}&amp;lt;/p&amp;gt;
       &amp;lt;p&amp;gt;Message: {state.message}&amp;lt;/p&amp;gt;
       &amp;lt;p&amp;gt;Timestamp: {state.timestamp}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
      &amp;lt;Link to="/"&amp;gt;Go Home&amp;lt;/Link&amp;gt;
    &amp;lt;/&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;You can now pass data with Link components or useNavigate hook from react-router-dom package provided you use the useLocation to get access to the passed data. If you feel i made a mistake, kindly hit me to tell me what i missed, thanks for reading.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Intersection observer  API</title>
      <dc:creator>thatFemicode</dc:creator>
      <pubDate>Mon, 08 Nov 2021 23:27:42 +0000</pubDate>
      <link>https://dev.to/thatfemicode/intersection-observer-api-3aop</link>
      <guid>https://dev.to/thatfemicode/intersection-observer-api-3aop</guid>
      <description>&lt;p&gt;Modern websites depend on scroll events that is the Cliché way of handling scrolling (window.scrollY). Scrolling can trigger lazy-loading of images and data and so much more. Unfortunately these scroll events are unreliable and intensive to use in my opinion and causes implementation issues which leads to poor browser performance.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Intersection Observer API&lt;/strong&gt; was created as a solution to solve the issues associated with "scroll events". It is  browser API that provides users a way to observe given elements and monitor changes in their intersection like the name says "INTERSECTION" with a given ancestor element or the viewport (Browser window) itself.&lt;/p&gt;

&lt;p&gt;Talking about the problem with the current implementation which is the scroll event. Consider a modern website , there are a lot of scroll events going on that we do not notice as users. The ads on the site load when scrolled into view, new contents load when the bottom of the page is reached, elements animate from time to time, and images are loaded lazily at times as the user reached them (Note: not all sites lazy load images). I myself have only done this once.  These scroll events rely basically on countless loops calling performance intensive methods like the &lt;strong&gt;Element.getBoundingClientRect()&lt;/strong&gt; to get the required position information. &lt;/p&gt;

&lt;p&gt;When these methods run, its all on the main thread and as we know JavaScript is a single threaded language meaning an issue with one causes a break in the code. ** The Intersection Observer API passes off management of intersection events to the browser by using callback functions tied to the intersection status of specific elements. The browser can manage these events more effectively, optimizing for performance.**&lt;/p&gt;

&lt;p&gt;The API is currently supported on most browsers, Chrome, Edge, Firefox and even Safari, which is pretty nice. &lt;/p&gt;

&lt;p&gt;Lets take a look at some of the Concepts and basic usage of the observer. &lt;/p&gt;

&lt;h1&gt;
  
  
  Concepts &amp;amp; Basic Usage
&lt;/h1&gt;

&lt;p&gt;To fully understand why the Intersection Observer API is so much better for performance, let’s start with a look at the basics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Definitions
&lt;/h2&gt;

&lt;p&gt;A few key terms are used to define any instance of an Intersection Observer. The root is the element which waits for an object to intersect it. By default, this is the browser viewport, but any valid element may be used.&lt;/p&gt;

&lt;p&gt;While the root element is the basis of a single IntersectionObserver, the observer can monitor many different targets. The target may also be any valid element, and the observer fires a callback function when any target intersects with the root element.&lt;/p&gt;

&lt;p&gt;Checkout the GIF in the link below to get a bit of visual representation. &lt;br&gt;
!(&lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zi0922bwgvzlrsz5p1u.gif"&gt;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zi0922bwgvzlrsz5p1u.gif&lt;/a&gt;) &lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;Setting up a simple IntersectionObserver is straightforward. First, call the IntersectionObserver constructor. Pass a callback function and desired options to the constructor function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const options = {
    root: document.querySelector('#viewport'),
    rootMargin: '0px',
    threshold: 1.0
};
const observer = new IntersectionObserver(callback, options);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As seen above, a few options are available to set in the constructor:&lt;/p&gt;

&lt;h3&gt;
  
  
  root
&lt;/h3&gt;

&lt;p&gt;The root is the element which is used to check for intersections of the target element. This option accepts any valid element, though it’s important that the root element be an ancestor of the target element for this to work. If a root isn’t specified (or null is the provided value), the browser viewport becomes the root.&lt;/p&gt;

&lt;h3&gt;
  
  
  rootMargin
&lt;/h3&gt;

&lt;p&gt;The rootMargin value is used to grow or shrink the size of the root element. Values are passed in a string, with a CSS-like format. A single value can be provided, or a string of multiple values to define specific sides (e.g. '10px 11% -10px 25px).&lt;/p&gt;

&lt;h3&gt;
  
  
  threshold
&lt;/h3&gt;

&lt;p&gt;Last, the threshold option specifies the minimum amount the target element must be intersecting the root for the callback function to fire. Values are floating point from 0.0 - 1.0, so a 75% intersection ratio would be 0.75. If you wish to fire the callback at multiple points, the option also accepts an array of values, e.g. ~[0.33, 0.66, 1.0]~.&lt;/p&gt;

&lt;p&gt;Once the IntersectionObserver instance is created, all that’s left is to provide one or more target elements for observation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const target = document.querySelector('#target');
observer.observe(target);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From here, the callback function will fire anytime the target(s) meet the threshold for intersection&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const callback = function(entries, observer) {
    entries.forEach((entry) =&amp;gt; {
        // do stuff here
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Calculation Intersections
&lt;/h2&gt;

&lt;p&gt;It’s important to understand how intersections are calculated. First, the Intersection Observer API considers everything to be a rectangle for the sake of this calculation. These rectangles are calculated to be the smallest they can possibly be, while still containing all target content.&lt;/p&gt;

&lt;p&gt;Check the GIF below to get a visual representation &lt;br&gt;
!(&lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8fiu3aiw33319pnqag5.gif"&gt;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8fiu3aiw33319pnqag5.gif&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Beyond the bounding boxes, consider any adjustments to the bounding box of the root element based on rootMargin values. These can pad or decrease the root size.&lt;/p&gt;

&lt;p&gt;Check out the GIF below to get a visual representation of the bove&lt;/p&gt;

&lt;p&gt;!(&lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbslr3nm3gik3kizccnq.gif"&gt;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbslr3nm3gik3kizccnq.gif&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Finally, it’s crucial to understand that unlike traditional scroll events, Intersection Observer isn’t polling constantly for every single change in intersection. Instead, the callback is only called when the provided threshold is reached (approximately). If multiple checks are required, simply provide multiple thresholds.&lt;/p&gt;

&lt;p&gt;You want to learn more, check out this series by Kevin Powell i used in getting an understanding of the intersection observer API&lt;br&gt;
Kevin Powell: &lt;a href="https://www.youtube.com/watch?v=T8EYosX4NOo&amp;amp;list=PLC2rzhluWUp-iWl6P2S7JG3xkHxeVCgBs"&gt;Link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>intersectionobserverapi</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Scope, Scope Chain and Lexical Environment 1</title>
      <dc:creator>thatFemicode</dc:creator>
      <pubDate>Mon, 23 Aug 2021 15:49:00 +0000</pubDate>
      <link>https://dev.to/thatfemicode/scope-scope-chain-and-lexical-environment-1-47e4</link>
      <guid>https://dev.to/thatfemicode/scope-scope-chain-and-lexical-environment-1-47e4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Scope in JavaScript is related to lexical environment and if you understand lexical environment you will understand scope, scope chain and also assist in understanding closure  i talked about last week. I hope this wont be too long because it took me a while before i got the understanding and i had to write extensively on it to better understand it, like i said there are different types of people and how we retain information is different. Lets Dive in 🛶.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function num(){
    console.log(c)
}
let c = 30
num()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Calling this function, JS engine (V8) in the browser will try to find c in the local memory space of the function num() when it is invoked.&lt;/p&gt;

&lt;p&gt;Running the code above we get 30 because V8 looked inside the function and did not find the variable inside the function and since the variable is not present inside that function local memory, it looks inside the &lt;strong&gt;GLOBAL&lt;/strong&gt; object, i am sure we all know what the &lt;strong&gt;GLOBAL&lt;/strong&gt; object is. &lt;br&gt;
&lt;strong&gt;NB&lt;/strong&gt;: Also like a trick i used to wrap this around in my head, the variable was executed in the global object so the variable c can be accessed via &lt;strong&gt;SCOPE CHAIN&lt;/strong&gt;, dont worry, we will see what &lt;strong&gt;SCOPE CHAIN&lt;/strong&gt; is after we touch on some concepts regarding lexical environment so the understanding can be better.&lt;/p&gt;

&lt;p&gt;Looking at another Instance of the function below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function num(){
    a()
function a(){
console.log(c)
}
}
let c = 30
a()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you think the output of this function will be? You can copy and paste the code in your browser console, it will be &lt;strong&gt;30&lt;/strong&gt; because invoking this function will also access the variable C in the global object (scope) and output 30 because function a() had to go up just 1 level in the scope chain to find the variable c which was inside the global object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function num(){
let c = 30
    a()
function a(){
console.log(c)
}
}
console.log(c)
a()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets go in another direction an try something now and access C when the variable is inside the function num() above, in this case what do you think the function will output? Try it in your console and see. It will output a reference  error saying C is not defined because the variable is locally scoped to that function and it cant be accessed outside the function. From all this done, we can say &lt;strong&gt;SCOPE&lt;/strong&gt; simply means where you can access a specific variable or a function in our code. From the examples above we asking, what is the scope of variable C like i said at the beginning, &lt;strong&gt;SCOPE&lt;/strong&gt; is dependent on the lexical environment. &lt;/p&gt;

&lt;p&gt;So as not to make this boring and too long because this was a lot to consume so digest on this and i will be posting the part2 of the article next week. &lt;br&gt;
Let me give some simple definitions that can be researched upon before the next article to better prepare&lt;/p&gt;

&lt;h2&gt;
  
  
  Lexical Environment
&lt;/h2&gt;

&lt;p&gt;Lexical environment simply means local memory along with lexical environment of its parent. &lt;br&gt;
What is Lexical? Lexical simply means hierarchy or in order and in coding terms, where that specific code is  present physically. Looking at the header for this post, those yellow shaded portions are regarded as lexical environment.&lt;/p&gt;

&lt;p&gt;Wow, this was a lot and hopefully you get the gist now, i always had issues understanding it till i read up and watched some videos that really explained the concept well, like i said at the beginning there are people who process information different and if you are a junior dev out there like me, this is probably for you. Thank you for reading. If anyone reading this feel like i made a mistake or my thought process for this was not explanatory enough, I'd be glad to receive advice (constructive criticism) and learn more. Have a great day and journey ahead.🚀♾&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>scopechain</category>
      <category>scope</category>
      <category>lexicalenvironment</category>
    </item>
    <item>
      <title>JavaScript Closures</title>
      <dc:creator>thatFemicode</dc:creator>
      <pubDate>Mon, 16 Aug 2021 11:48:01 +0000</pubDate>
      <link>https://dev.to/thatfemicode/javascript-closures-ldg</link>
      <guid>https://dev.to/thatfemicode/javascript-closures-ldg</guid>
      <description>&lt;h2&gt;
  
  
  Closures
&lt;/h2&gt;

&lt;p&gt;Yes i finally found the courage to post about topics i have been learning and documenting about this past few months after. Its time i start putting my self out there and haring knowledge whilst learning because hoarding and not sharing what you have learnt as you continue on your journey wont help the next set of engineers coming in as there might be just that one person that processes information the same way you do, i myself, definitely not the smartest person so i have mechanisms that i use to study, for the better part of my coding journey i didnt really use my studying mechanism but rather used something i always labelled as  Photographic memory to Understand concepts which i found out was not working for me, ever since going back to my default settings, lol, i began to get a good grasp of concepts very well, not to digress, this is a discussion for another day. Lets get into the main thing &lt;strong&gt;JAVASCRIPT CLOSURES&lt;/strong&gt;. This will be really short&lt;/p&gt;

&lt;h2&gt;
  
  
  What are closures or what is a closure? 🤔
&lt;/h2&gt;

&lt;p&gt;Closure can be simply defined as simply a function bundled together with reference to its &lt;strong&gt;LEXICAL ENVIRONMENT&lt;/strong&gt; i.e.(Parent Scope). We probably use closures at times and we dont even know we do, hell i worked on something a while back and didnt even know 😂&lt;br&gt;
Lets look at it from this angle: a function which is a first-class object in JS has something like a family tree, the function in this case being the father built a house and has children in this case a child which is the function that is returning, those children or that child will always remember that house even after the father dies or in the case of our functions gets executed, because they were or he/she was  brought up in that house, if the house has a chair, the children or child in this case the functions will always remember the color of the chair. Get it now? If you dont let us take simple function and explain this concept&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function father(){
let chairColour = "red"
function childOne(){
console.log(chairColour)
}
return childOne
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Calling father() will just be called or invoked but nothing will happen but calling father()() something like an IFFE will return the chairColor&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;or you can do something like this
let child = father()
child()
in this case we call the father, it gets executed and returns a child to continue with its Legacy, permit me to say this. Lol
then the child gets the child variable gets the returned function and can then be called
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;something like a the Scope chain where the returned function will look up its family tree and remember &lt;em&gt;"Oh i cant find the variable or common thing in my own family house but its in my fathers house where i grew up"&lt;/em&gt;. Not to make this very long as this is my first article and i would not want to bore you. so lets talk about the Advantages and disadvantages of function&lt;br&gt;
&lt;strong&gt;ADVANTAGES&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Data Privacy and Encapsulation (Variables in functions that are not accessible outside that function)&lt;/li&gt;
&lt;li&gt;Memoize &amp;amp;&amp;amp; Once (This two are higher order functions, i myself do not really know what they are lol, hopefully i get to explore them)&lt;/li&gt;
&lt;li&gt;Function currying&lt;/li&gt;
&lt;li&gt;Module pattern(A concept in JavaScript)
&lt;strong&gt;Disadvantages&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Memory Leaks&lt;/li&gt;
&lt;li&gt;Overconsumption of memory because anytime a closure is formed because those closed variables are not garbage collected. It is just accumulating a lot of memory. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What is Garbage Collector?&lt;br&gt;
It is a program in browser or JS engine which frees up unutilized memory because JS is a high level language.&lt;/p&gt;

&lt;p&gt;Hopefully you get the gist of how closures behave now, i always had issues understanding it till i read up and watched some videos that really explained the concept well,  like i said at the beginning there are people who process information different and if you are a junior dev out there like me, this is probably for you. Thank you for reading. If anyone reading this feel like i made a mistake or my thought process for this was not explanatory enough, I'd be glad to receive advice (constructive criticism) and learn more. Have a great day and journey ahead.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
