<?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: Phyllis Kan</title>
    <description>The latest articles on DEV Community by Phyllis Kan (@pkangithub).</description>
    <link>https://dev.to/pkangithub</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%2F438064%2F748a7350-fd06-48e2-b988-d2f7c3698ee5.png</url>
      <title>DEV Community: Phyllis Kan</title>
      <link>https://dev.to/pkangithub</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pkangithub"/>
    <language>en</language>
    <item>
      <title>Hoisting in Js</title>
      <dc:creator>Phyllis Kan</dc:creator>
      <pubDate>Mon, 10 Aug 2020 19:39:30 +0000</pubDate>
      <link>https://dev.to/pkangithub/hoisting-in-js-5hn5</link>
      <guid>https://dev.to/pkangithub/hoisting-in-js-5hn5</guid>
      <description>&lt;h2&gt;
  
  
  What is Hoisting?
&lt;/h2&gt;

&lt;p&gt;When we look up what is hoisting in JS, we will be most likely to get this explanation:&lt;br&gt;
*behavior of moving declarations of variable and function to the top of their current scope. *&lt;/p&gt;

&lt;p&gt;what does that mean? &lt;/p&gt;

&lt;p&gt;In JS, there is two phases of hoisting:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is going to scan for all of the declared variable and function when the program runs from top all the way through the end and put them into the memory of Lexical Scope.&lt;/li&gt;
&lt;li&gt;It is going to start implement the these variable and function from the top, execute them line by line,   since these functions and variable have already been created in the memory.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Difference Between &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;var&lt;/code&gt; in Hoisting
&lt;/h3&gt;

&lt;p&gt;So  lets see how hoisting work in &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;var&lt;/code&gt; :&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;var&lt;/code&gt; variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//output 'undefined'&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;why is it undefined when we are expecting the number 10? &lt;/p&gt;

&lt;p&gt;It is because JS hoist only hoist the declaration, not their assignment which is the value.&lt;br&gt;
So when &lt;code&gt;num&lt;/code&gt; is called in the console.log, the lexical scope will only initialize it with undefined. And when the execution reached where the assignment is done, it'll then update the value to 10.&lt;/p&gt;

&lt;p&gt;Where for &lt;code&gt;let&lt;/code&gt; variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: num is not defined&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;why the num is 'not' defined instead of undefined like &lt;code&gt;var&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;All declarations with function, var, let, ...etc are hoisted in JS, but only &lt;code&gt;var&lt;/code&gt; is initialized with undefined in lexical scope, while &lt;code&gt;let&lt;/code&gt; remains uninitialized and it will only to be initialized when their lexical assignment is evaluated during the runtime by the JavaScript engine. Which means it cannot access the variable before it is assigned to a value at where it was declared in the code.&lt;/p&gt;

&lt;p&gt;Blog post moved from my Learn blog &lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Redux: Understanding Redux Flow</title>
      <dc:creator>Phyllis Kan</dc:creator>
      <pubDate>Mon, 10 Aug 2020 19:36:52 +0000</pubDate>
      <link>https://dev.to/pkangithub/redux-understanding-redux-flow-106j</link>
      <guid>https://dev.to/pkangithub/redux-understanding-redux-flow-106j</guid>
      <description>&lt;p&gt;Before I started on my final project, I still find myself confused with the subject React and Redux. However, as I work on them with more familiar topic, it is easier to understand React, but for Redux, lets talk about it... &lt;/p&gt;

&lt;p&gt;I've heard many of my cohorts and friends saying Redux is an overkill for our project, since we only touch on this topic for a short period of time that the project we decided to make isn't going to be big enough to need Redux. So...&lt;/p&gt;

&lt;h2&gt;
  
  
  WHY DO WE NEED Redux?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;This may not be the best example, but lets use bank as an example to describe each flow.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redux Cycle =  Action Creator -&amp;gt; Actions -&amp;gt; Dispatch -&amp;gt; Reducers -&amp;gt; Store/State&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Action Creator&lt;/strong&gt; is a function that is going to create or return plain javascript object(Action)&lt;br&gt;&lt;br&gt;
&lt;em&gt;Ex. A client in the bank&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Action&lt;/strong&gt; is a "message" to the reducer describing the change wanted inside of our app.&lt;br&gt;&lt;br&gt;
&lt;em&gt;Ex. A slip for withdraw or deposit (noun)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dispatch&lt;/strong&gt; function is going to take in an action and going to make a copy of that object and passed it off to different places inside of our application.(verb)&lt;br&gt;&lt;br&gt;
&lt;em&gt;Ex. Speaking to the teller of what is needed to be done&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reducer&lt;/strong&gt; is a function that is responsible to taking in an action and some existing amount of data and it's going to process that action and then make some change of the data and then return it, so it can then be use in other location with store.&lt;br&gt;
&lt;em&gt;Ex. The teller takes the slip and go take the money out of the vault for withdraw, or put the money in for deposit.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  --------------------------------------------------------
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Middleware(thunk)&lt;/strong&gt; is needed when you are working with async code, thunk is the middleware we were taught to use that when the need of middleware comes(for promises), your action creator and action will become async action creator and async action. It is part of your app as it is like a bridge for your API call to your action dispatch. They don't deal with the store directly, but you can't have them to be left out if you want specific job done.&lt;br&gt;&lt;br&gt;
&lt;em&gt;Ex. Bank manager. When a client request a large withdraw, tellers needs to get permission from the bank manager before they can continue do what is asked.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;REDUX STORE(Ex. vault): &lt;/p&gt;

&lt;p&gt;This is more of visual look of why the Redux Store is needed in big appliacations.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0*--0--0--0--O--0--0--0--0*&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Note: The middle &lt;code&gt;O&lt;/code&gt; is the &lt;code&gt;App.js&lt;/code&gt; component&lt;/p&gt;

&lt;p&gt;lets say the first &lt;code&gt;0*&lt;/code&gt; is a nested component which is inside of the component on the right and so on. All the way into &lt;code&gt;App.js&lt;/code&gt; component. Meanwhile, the same for the right end side &lt;code&gt;0*&lt;/code&gt; sending toward the center.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;App.js&lt;/code&gt; has 2 component inside of them.  &lt;/p&gt;

&lt;p&gt;And lets say the &lt;code&gt;0*&lt;/code&gt; on the right-end has a thing that changes the state, like for example if you press a button, it'll add 1 to your score. &lt;/p&gt;

&lt;p&gt;But what if your left-end&lt;code&gt;0*&lt;/code&gt; component also need the access to the score, then all you'll have to do is string all the right &lt;code&gt;0&lt;/code&gt; together so when you press the button, it'll initiated to right &lt;code&gt;0*&lt;/code&gt;component and to send it up one by one to the left all the way to the &lt;code&gt;App.js&lt;/code&gt; just so you can change the state, and also one by one update it all the way to the left-end &lt;code&gt;0*&lt;/code&gt; so it have access to it. You probably can already tell, if this is a large application, then it gets very tedious.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SO WHAT REDUX DOES&lt;/strong&gt; is to creates a single immutable store and Redux allows components to have access to that store no matter where they're at, which means if you got redux loaded in your app, you can just &lt;code&gt;connect&lt;/code&gt; the components to Redux and when that component changes the score, it's equally accessible to all your connected components.&lt;/p&gt;

&lt;p&gt;So it will automatically update on the left end &lt;code&gt;0*&lt;/code&gt; without passing all the way from right end &lt;code&gt;0*&lt;/code&gt; one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope this may help some of you understand Redux better, as it is really complicated as you first encounter them. And it is normal to felt this way. A friend of mine who is working in this field also said, "Developers spend 2-6 months working with redux before they finally understand it", so don't feel like you are not smart enough(like I did, but afterwards I heard the same for most of my cohorts). However, note that Redux can be very useful when we started to work on bigger projects.&lt;/p&gt;

&lt;p&gt;Blog post moved from my Learn blog &lt;/p&gt;

</description>
      <category>redux</category>
    </item>
    <item>
      <title>Props vs State in React</title>
      <dc:creator>Phyllis Kan</dc:creator>
      <pubDate>Mon, 10 Aug 2020 19:30:08 +0000</pubDate>
      <link>https://dev.to/pkangithub/props-vs-state-in-react-if</link>
      <guid>https://dev.to/pkangithub/props-vs-state-in-react-if</guid>
      <description>&lt;p&gt;Trying to differentiate state and prop would be one of the most conceptually confusing for beginners in React, so I break it down into points.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Props(properties)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Components receive data from outside the component with props.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Are what we use to pass data between our components in React which it only goes from parent to child component. So components receive data from parent component with props.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Props can be anything. they can be strings, arrays, objects, functions, etc. &lt;strong&gt;Callback function&lt;/strong&gt; can also be passed as prop to initiate it’s state changes(updating state) from the child component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;One limit to props is that it is immutable, meaning you shouldn’t ever directly change the value of props.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;State&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Components can create and manage their own local state&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;State is mutable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When state changes, it trigger updates in components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Great thing about state is that it’ll only update part of the app component that is influence by the data changes instead of updating the whole app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;State should not be modified directly, but it can be modified with a special method called &lt;code&gt;setState&lt;/code&gt; (Class Component) &lt;strong&gt;OR&lt;/strong&gt; using React hook (Functional Component)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Blog post moved from my Learn blog &lt;/p&gt;

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