{"id":1496,"date":"2021-04-19T10:56:58","date_gmt":"2021-04-19T10:56:58","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=1496"},"modified":"2021-04-19T10:56:59","modified_gmt":"2021-04-19T10:56:59","slug":"reactjs-a-new-app-tns","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2021\/04\/19\/reactjs-a-new-app-tns\/","title":{"rendered":"ReactJS: A new app `tns`"},"content":{"rendered":"<p>I need to write an app for a friend and what better way to brush up old concepts and write a fresh blog in doing so. So here I am, trying to put together some old and new skills together to help create a simple webapp that will have a dashboard and basic login enabled.<\/p>\n\n\n<h2 class=\"wp-block-heading\">Step &#8211; 1:<\/h2>\n\n\n\n<p><code>create-react-app tns<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>success! Created tns at \/home\/saurabh\/sourcebox\/reactjs\/tns\nInside that directory, you can run several commands:\n\n  npm start\n    Starts the development server.\n\n  npm run build\n    Bundles the app into static files for production.\n\n  npm test\n    Starts the test runner.\n\n  npm run eject\n    Removes this tool and copies build dependencies, configuration files\n    and scripts into the app directory. If you do this, you can\u2019t go back!\n\nWe suggest that you begin by typing:\n\n  cd tns\n  npm start\n\nHappy hacking!\n<\/code><\/pre>\n\n\n\n<p>as suggested let&#8217;s <code>cd<\/code> into <code>tns<\/code> and do <code>npm start<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"885\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/terminal-launch-1024x885.png\" alt=\"\" class=\"wp-image-1498\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/terminal-launch-1024x885.png 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/terminal-launch-300x259.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/terminal-launch-768x663.png 768w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/terminal-launch.png 1219w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"562\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/app-main-page.-1024x562.png\" alt=\"\" class=\"wp-image-1499\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/app-main-page.-1024x562.png 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/app-main-page.-300x165.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/app-main-page.-768x421.png 768w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/app-main-page.-1536x842.png 1536w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/app-main-page..png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The code files that it generates are as under<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drwxrwxr-x    6 saurabh saurabh   4096 Apr 17 18:03 .\/\ndrwxrwxr-x    3 saurabh saurabh   4096 Apr 17 17:41 ..\/\ndrwxrwxr-x    8 saurabh saurabh   4096 Apr 17 18:04 .git\/\n-rw-rw-r--    1 saurabh saurabh    310 Apr 17 17:43 .gitignore\ndrwxrwxr-x 1061 saurabh saurabh  36864 Apr 17 17:50 node_modules\/\n-rw-rw-r--    1 saurabh saurabh    807 Apr 17 17:43 package.json\n-rw-rw-r--    1 saurabh saurabh 692900 Apr 17 17:43 package-lock.json\ndrwxrwxr-x    2 saurabh saurabh   4096 Apr 17 17:43 public\/\n-rw-rw-r--    1 saurabh saurabh   3369 Apr 17 17:43 README.md\ndrwxrwxr-x    2 saurabh saurabh   4096 Apr 17 17:43 src\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Folder<\/code> <code>src\/<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>.\n\u251c\u2500\u2500 App.css\n\u251c\u2500\u2500 App.js\n\u251c\u2500\u2500 App.test.js\n\u251c\u2500\u2500 index.css\n\u251c\u2500\u2500 index.js\n\u251c\u2500\u2500 logo.svg\n\u251c\u2500\u2500 reportWebVitals.js\n\u2514\u2500\u2500 setupTests.js<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Main component<\/h2>\n\n\n\n<p>The boiler plate code generates the first component for us.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function App() {\n  return (\n    &lt;div className=\"App\">\n      &lt;header className=\"App-header\">\n        &lt;img src={logo} className=\"App-logo\" alt=\"logo\" \/>\n        &lt;p>\n          Edit &lt;code>src\/App.js&lt;\/code> and save to reload.\n        &lt;\/p>\n        &lt;a\n          className=\"App-link\"\n          href=\"https:\/\/reactjs.org\"\n          target=\"_blank\"\n          rel=\"noopener noreferrer\"\n        >\n          Learn React\n        &lt;\/a>\n      &lt;\/header>\n    &lt;\/div>\n  );\n}\n\nexport default App;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Index.html<\/h2>\n\n\n\n<p>It defines the binding where to put in the component<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &lt;body>\n    &lt;noscript>You need to enable JavaScript to run this app.&lt;\/noscript>\n    &lt;!-- The main root element -->\n    &lt;div id=\"root\">&lt;\/div>\n  &lt;\/body><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Adding some <code>Welcome Name<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>function Welcome({ myName }) {\n  return &lt;p> Welcome {myName}&lt;\/p>\n}<\/code><\/pre>\n\n\n\n<p><code>myName<\/code> is an attribute that I will be passing to this element, which will be referenced from the main app.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Welcome myName=\"Mr. Saurabh\">&lt;\/Welcome><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"881\" height=\"608\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/newcomponent.png\" alt=\"\" class=\"wp-image-1501\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/newcomponent.png 881w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/newcomponent-300x207.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/04\/newcomponent-768x530.png 768w\" sizes=\"(max-width: 881px) 100vw, 881px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Help<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>React official documentation (<a href=\"https:\/\/reactjs.org\/docs\/getting-started.html\">link<\/a>)<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I need to write an app for a friend and what better way to brush up old concepts and write a fresh blog in doing so. So here I am, trying to put together some old and new skills together to help create a simple webapp that will have a dashboard and basic login enabled. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1501,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[179],"class_list":["post-1496","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-reactjs","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=1496"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1496\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/1501"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=1496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=1496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=1496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}