<?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: Jack Chen</title>
    <description>The latest articles on DEV Community by Jack Chen (@chenchengxing).</description>
    <link>https://dev.to/chenchengxing</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%2F500636%2F7f43627c-024f-43d1-a7e4-d7e19ad61283.jpeg</url>
      <title>DEV Community: Jack Chen</title>
      <link>https://dev.to/chenchengxing</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chenchengxing"/>
    <language>en</language>
    <item>
      <title>After reviewing JS fundamentals, I found that Create-React-App is doing a lot..</title>
      <dc:creator>Jack Chen</dc:creator>
      <pubDate>Mon, 16 Nov 2020 02:12:53 +0000</pubDate>
      <link>https://dev.to/chenchengxing/after-reviewing-js-fundamentals-i-found-that-create-react-app-is-doing-a-lot-2mph</link>
      <guid>https://dev.to/chenchengxing/after-reviewing-js-fundamentals-i-found-that-create-react-app-is-doing-a-lot-2mph</guid>
      <description>&lt;p&gt;In normal daily life, I work on create-react-app project without thinking..&lt;/p&gt;

&lt;p&gt;Recently, I reviewed JS fundamentals. Then I realized how great create-react-app is and there're lots of assumptions wrong in my head&lt;/p&gt;

&lt;h2&gt;
  
  
  Assumption #1
&lt;/h2&gt;

&lt;p&gt;Syntax and ES features I'm using are supported in browsers for sure..&lt;/p&gt;

&lt;p&gt;In fact, it's not true. CRA is filling the gap by having compilers transforming your code to the target, es5, es6, or others. And also, The gap for ES features are filled by polyfills someone added to the project. It's possibly done by yourself!&lt;/p&gt;

&lt;p&gt;My point is you don't need to touch or think about these and you tend to forget. That's why I'm writing it down to remind myself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ES6&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;count&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;// syntactic feature&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&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="c1"&gt;// functional feature&lt;/span&gt;

&lt;span class="c1"&gt;// ⬇️⬇️compiled to ES5&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// syntactic feature&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{});&lt;/span&gt; &lt;span class="c1"&gt;// functional feature&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above shown how it's compiled in Babel say you write ES6 code or the latest fancy code then the target is set to ES5.&lt;/p&gt;

&lt;p&gt;Note that the syntactic feature is handled or changed in the output which is compatible with ES5. BUT, the functional feature is not handled, which is why polyfills should kick in. Great explanation &lt;a href="https://stackoverflow.com/questions/50986494/what-does-the-typescript-lib-option-really-do/57474312#57474312"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Assumption #2
&lt;/h2&gt;

&lt;p&gt;You can import anything: css, image, module, even &lt;a href="https://create-react-app.dev/docs/code-splitting/"&gt;import dynamically&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The mighty webpack is behind CRA, that's why all these magic is available.&lt;/p&gt;

&lt;h2&gt;
  
  
  Others
&lt;/h2&gt;

&lt;p&gt;Also tonnes of recommendations like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how to test with jest, react-testing-lib&lt;/li&gt;
&lt;li&gt;how to handle HTML Head with ReactHelmet&lt;/li&gt;
&lt;li&gt;how to deploy&lt;/li&gt;
&lt;li&gt;how to work with backend&lt;/li&gt;
&lt;li&gt;how to opt-in PWA&lt;/li&gt;
&lt;li&gt;how to fetch data&lt;/li&gt;
&lt;li&gt;how to config Env Variables&lt;/li&gt;
&lt;li&gt;how to analyze your app&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It would be a nightmare if you have to do all these. And thanks to CRA, we just need to kick in whenever it's needed.&lt;/p&gt;

</description>
      <category>react</category>
      <category>cra</category>
    </item>
    <item>
      <title>Migration to Typescript in a React app</title>
      <dc:creator>Jack Chen</dc:creator>
      <pubDate>Wed, 11 Nov 2020 03:33:12 +0000</pubDate>
      <link>https://dev.to/chenchengxing/migration-to-typescript-in-a-react-app-2hg6</link>
      <guid>https://dev.to/chenchengxing/migration-to-typescript-in-a-react-app-2hg6</guid>
      <description>&lt;p&gt;Recently, I was working on a project which started in 2018. It was setup with React, Redux, Mui.. There're quite a lot of features and pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem or why we move to Typescript
&lt;/h2&gt;

&lt;p&gt;I was assigned to a task that seemed really easy, which is to display the correct phone number for user logged in.&lt;/p&gt;

&lt;p&gt;BUT when I digged into that, I found that it's really hard to figure out the shape of profile data for user. The origin data is passing around and name got changed accross different adaptors. To make things worse, the comments are out-dated.&lt;/p&gt;

&lt;p&gt;I really want something like this, which makes everything clear:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;OriginProfile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;primaryPhone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Profile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;phoneNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&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;h2&gt;
  
  
  How we did it
&lt;/h2&gt;

&lt;p&gt;Basically we did it one component after another. Whenever there's a task that requires us to make changes to the code.&lt;br&gt;
We tried to migrate the related files to typescript. Luck that typescript is a superset of javascript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rename as we go
&lt;/h3&gt;

&lt;p&gt;Rename .js/jsx to .ts/tsx.&lt;/p&gt;

&lt;h3&gt;
  
  
  Infer the shape
&lt;/h3&gt;

&lt;p&gt;To define the shape the data, we have to infer that from the logic in code and the response payload. We did our best to infer and it doesn't matter if we miss something, because we can always add more.&lt;/p&gt;

&lt;h3&gt;
  
  
  To make the code running
&lt;/h3&gt;

&lt;p&gt;To fix the errors, be flexible and nice.. Just make use of &lt;code&gt;any&lt;/code&gt; magic, every error will go away :)&lt;br&gt;
At this point, you should realize you wrote code by guessing.. It's really luck that it worked..&lt;/p&gt;

&lt;h3&gt;
  
  
  linting
&lt;/h3&gt;

&lt;p&gt;By adding &lt;code&gt;eslint-disable&lt;/code&gt; is useful to make code work as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  remove PropTypes
&lt;/h3&gt;

&lt;p&gt;At this point, I really can't see any benefits to have the PropTypes because Typescript is really helpful in defining the shape. So PropTypes is redundant, that's why we remove it.&lt;br&gt;
Instead we have &lt;code&gt;Interface Props {}&lt;/code&gt; for every component.&lt;/p&gt;

&lt;h2&gt;
  
  
  How's the feeling
&lt;/h2&gt;

&lt;p&gt;It's not easy at the beginning, because I have to figure out how to eliminate all the errors and lots of basic entity typings needed in the project.&lt;/p&gt;

&lt;p&gt;But it gets better when you know how to use &lt;code&gt;any&lt;/code&gt; and once most of the entity types are defined, not much left indeed, or you can say, it's much easier to add new type.&lt;/p&gt;

&lt;p&gt;What's important is that you become much more confident in coding. Typescript will scream if something is wrong. You trust the code, and you know exactly what you're dealing with. Is it a number, string, an object, some complex entity, is it possibly null. You know all that without guessing!&lt;/p&gt;

&lt;p&gt;Typescript is awesome and I guess I will never go back.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
    </item>
    <item>
      <title>Redux vs Mobx in React state management in 2020</title>
      <dc:creator>Jack Chen</dc:creator>
      <pubDate>Wed, 11 Nov 2020 02:55:58 +0000</pubDate>
      <link>https://dev.to/chenchengxing/redux-vs-mobx-in-react-state-management-in-2020-5gkb</link>
      <guid>https://dev.to/chenchengxing/redux-vs-mobx-in-react-state-management-in-2020-5gkb</guid>
      <description>&lt;p&gt;Wow, I just tried to tag this post with &lt;code&gt;mobx&lt;/code&gt;, but no suggestion..&lt;/p&gt;

&lt;p&gt;I want to make a comparison between Redux and Mobx. Here are my contrived simple apps showing &lt;strong&gt;notifications&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://codesandbox.io/s/react-redux-examplecomparison-with-mobx-kxv4x?file=/src/store.js" rel="noopener noreferrer"&gt;Redux one&lt;/a&gt;
&lt;iframe src="https://codesandbox.io/embed/react-redux-examplecomparison-with-mobx-kxv4x"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://codesandbox.io/s/mobx-lite-state-management-example-6ie7w?file=/src/NotificationList.js:165-178" rel="noopener noreferrer"&gt;Mobx one&lt;/a&gt;
&lt;iframe src="https://codesandbox.io/embed/mobx-lite-state-management-example-6ie7w"&gt;
&lt;/iframe&gt;

&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="c1"&gt;// shapes&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;notifications&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="nf"&gt;setNotifications&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;notifications&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;[]):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;prependNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;notification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Notification&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&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;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw36cpirh7slpza2kl5t1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw36cpirh7slpza2kl5t1.png" alt="react_redux_example_comparison_with_Mobx__-_CodeSandbox"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown above, the shape of main store and the display is very simple and contrived.&lt;br&gt;
The app is showing all the notifications with contents. &lt;br&gt;
Two behaviours:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;set initial notifications&lt;/li&gt;
&lt;li&gt;get the latest notification and show on the top&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Mobx solution
&lt;/h2&gt;

&lt;p&gt;The key here is &lt;code&gt;useNotifications&lt;/code&gt; hook which exports &lt;code&gt;useContext&lt;/code&gt; result with an observable managed by MobX magic&lt;br&gt;
&lt;/p&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;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;observable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;notifications&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;setNotifications&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;action&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;notifications&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;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;notifications&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;notifications&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="na"&gt;prependNotification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;action&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;notification&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;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setNotifications&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;notification&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;notifications&lt;/span&gt;&lt;span class="p"&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;p&gt;It's very easy to think of and use. Just simply call &lt;code&gt;useNotifcations&lt;/code&gt; hook anywhere you want to get hold of the actions or notifications data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Only thing you want to keep in mind
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;observer&lt;/code&gt; to wrap your component otherwise the component will not react to the change! like &lt;code&gt;observer(NotificationList)&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Redux solution
&lt;/h2&gt;

&lt;p&gt;I think we should skip the setup part like wrapping the app with &lt;code&gt;Provider&lt;/code&gt; and combining reducers.&lt;/p&gt;

&lt;p&gt;The key part here is notification reducer and how to change the state via actions. That said, we have to keep the &lt;code&gt;action -&amp;gt; reducer -&amp;gt; state&lt;/code&gt; in mind all the time while using redux. That's something I don't like.&lt;/p&gt;

&lt;p&gt;To make all things working, boilerplate is needed. You have to setup actions in unique names, setup big switch statement to distribute the reducer logic.&lt;/p&gt;

&lt;p&gt;To fire an action in component, it's much easier now. The only thing you need is &lt;code&gt;useDispatch()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To use a state in component, simply use &lt;code&gt;useSelector()&lt;/code&gt; to get hold of the piece you want from root reducer.&lt;/p&gt;

&lt;h2&gt;
  
  
  My recommendation
&lt;/h2&gt;

&lt;p&gt;Use MobX, it's much easier and straightforward. You define the shape you want in store, then easily get hold of and easily make change of it.&lt;/p&gt;

&lt;p&gt;By using Redux, you need to have the action, reducer flow in mind. Also if you're using typescript, oh.. you might need to have a lot more boilerplate.&lt;/p&gt;

&lt;p&gt;Maybe Redux does have a larger community which may provide more support and maybe more tools for Redux. But still, I like MobX more.&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>mobx</category>
    </item>
    <item>
      <title>React, why we need state management and how we can do it well</title>
      <dc:creator>Jack Chen</dc:creator>
      <pubDate>Sun, 08 Nov 2020 23:39:24 +0000</pubDate>
      <link>https://dev.to/chenchengxing/react-why-we-need-state-management-and-how-we-can-do-it-well-59p3</link>
      <guid>https://dev.to/chenchengxing/react-why-we-need-state-management-and-how-we-can-do-it-well-59p3</guid>
      <description>&lt;p&gt;State management seems like a fancy word. But however you put it, we need to manage it or deal with it in some ways.&lt;/p&gt;

&lt;p&gt;Think in this way: the application is like a state-machine which goes from one state to another. And that means we can have lots of states in our app which can be decided or derived from variables or values.&lt;/p&gt;

&lt;p&gt;The way we're handling all these variables or values is called state management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common State Levels through out
&lt;/h2&gt;

&lt;h3&gt;
  
  
  State in Component level
&lt;/h3&gt;

&lt;p&gt;In old times, we can use &lt;code&gt;state&lt;/code&gt; &lt;code&gt;setState()&lt;/code&gt; to get hold of and change state.&lt;/p&gt;

&lt;p&gt;With the help of hooks, simply &lt;code&gt;[state, setState] = useState()&lt;/code&gt; will do&lt;/p&gt;

&lt;h3&gt;
  
  
  State in Page level
&lt;/h3&gt;

&lt;p&gt;Similar to state in component, you can treat it as a Page Compenent.&lt;/p&gt;

&lt;p&gt;Things to note here is that at some point you have to use it and maybe you have to pass it to the child component which can be really deep.&lt;/p&gt;

&lt;h3&gt;
  
  
  State in Application level
&lt;/h3&gt;

&lt;p&gt;Believe me, we have those things like Global Snackbar or Global Banner which are those things that only have one instance or have only one state to represent it in the whole application.&lt;/p&gt;

&lt;p&gt;We can of course manage it in the root component and pass it down deep, but don't..&lt;/p&gt;

&lt;h2&gt;
  
  
  How to deal with it or manage it
&lt;/h2&gt;

&lt;h3&gt;
  
  
  State in Component level
&lt;/h3&gt;

&lt;p&gt;Just use hooks, it's easy and effective.&lt;/p&gt;

&lt;h3&gt;
  
  
  State in Page and Application level
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;React.Context&lt;/code&gt; or third party &lt;code&gt;Mobx&lt;/code&gt; or &lt;code&gt;Redux&lt;/code&gt; to manage it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;React.Context way: &lt;a href="https://kentcdodds.com/blog/application-state-management-with-react/" rel="noopener noreferrer"&gt;https://kentcdodds.com/blog/application-state-management-with-react/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mobx way &lt;a href="https://mobx.js.org/react-integration.html#using-external-state-in-observer-components" rel="noopener noreferrer"&gt;https://mobx.js.org/react-integration.html#using-external-state-in-observer-components&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Redux way &lt;a href="https://react-redux.js.org/introduction/quick-start#quick-start" rel="noopener noreferrer"&gt;https://react-redux.js.org/introduction/quick-start#quick-start&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  My Recommendation
&lt;/h2&gt;

&lt;p&gt;There's no holy grails here. You can choose to do it in any way. But to me, it's very easy and straightfoward to go with the &lt;strong&gt;Mobx&lt;/strong&gt; way.&lt;/p&gt;

&lt;p&gt;With the Mobx way, you can easily define the state you want. No hierachy needed. The state doesn't have to be tied to a root. They can be managed as individuals just as they might be.&lt;/p&gt;

&lt;p&gt;The idea is very much like it's in Recoil.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fluey3veejbilop0gsn2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fluey3veejbilop0gsn2r.png" alt="react_recoil_-_Google_Search"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's also amazing to get hold of the state and update with the help of &lt;code&gt;useContext&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;No more redux boilerplates, no more Providers, so why not?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create Github-Pages in create-react-app project</title>
      <dc:creator>Jack Chen</dc:creator>
      <pubDate>Wed, 28 Oct 2020 06:55:10 +0000</pubDate>
      <link>https://dev.to/chenchengxing/create-github-pages-in-create-react-app-project-no2</link>
      <guid>https://dev.to/chenchengxing/create-github-pages-in-create-react-app-project-no2</guid>
      <description>&lt;p&gt;Today I tried to create a gh-page for my &lt;a href="https://github.com/chenchengxing/minesweeper"&gt;minesweeper project&lt;/a&gt;. Nothing fancy but I just want to publish it somewhere. It turns out to be pretty easy to do that and it was a success. Result is &lt;a href="https://chenchengxing.github.io/minesweeper/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Search around
&lt;/h2&gt;

&lt;p&gt;I thought it's only possible to host only one github page under one account name, like jackchen.github.io. But I was wrong, according to &lt;a href="https://pages.github.com/"&gt;https://pages.github.com/&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;In fact any github user can have unlimited project sites.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A9xw-8X1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/on1xzzj1pme4v8rwxivi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9xw-8X1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/on1xzzj1pme4v8rwxivi.png" alt="GitHub_Pages___Websites_for_you_and_your_projects__hosted_directly_from_your_GitHub_repository__Just_edit__push__and_your_changes_are_live_"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  npm package gh-pages
&lt;/h2&gt;

&lt;p&gt;The next step will be creating a new branch that contains all the static files.&lt;/p&gt;

&lt;p&gt;But it doesn't sound right to do it manually. &lt;/p&gt;

&lt;p&gt;Then I found this &lt;a href="https://www.npmjs.com/package/gh-pages"&gt;https://www.npmjs.com/package/gh-pages&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Basically, &lt;code&gt;gh-pages&lt;/code&gt; will help you push files under some certain folder only to 'gh-pages' branch(configurable).&lt;/p&gt;

&lt;h2&gt;
  
  
  Just do it
&lt;/h2&gt;

&lt;p&gt;So it seemed pretty straightforward until I hit something..&lt;/p&gt;

&lt;p&gt;BTW, I'm using create-react-app for my project.&lt;br&gt;
I went &lt;code&gt;yarn run build&lt;/code&gt;, then run the &lt;code&gt;gh-pages&lt;/code&gt; script. So all my build folder went to the correct branch.&lt;/p&gt;

&lt;p&gt;But the site didn't work.&lt;br&gt;
I found that the index.html was loading correctly but not other resources. So I can tell something is wrong in PUBLIC_URL.&lt;/p&gt;

&lt;p&gt;By running, according to creact-react-app &lt;a href="https://create-react-app.dev/docs/advanced-configuration/"&gt;documentation&lt;/a&gt;, to &lt;code&gt;PUBLIC_URL=. react-scripts build&lt;/code&gt; did work!&lt;/p&gt;

&lt;h2&gt;
  
  
  can it be better?
&lt;/h2&gt;

&lt;p&gt;Yes.. I found this &lt;a href="https://create-react-app.dev/docs/deployment/#github-pages"&gt;https://create-react-app.dev/docs/deployment/#github-pages&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It turns out create-react-app has already got it covered. Amazing!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
