{"id":1102,"date":"2020-08-05T20:39:02","date_gmt":"2020-08-05T15:09:02","guid":{"rendered":"http:\/\/www.prasadk.com\/my-press\/?p=1102"},"modified":"2020-08-05T20:39:08","modified_gmt":"2020-08-05T15:09:08","slug":"kick-start-react-native-with-basics-stack-navigation","status":"publish","type":"post","link":"https:\/\/www.prasadk.com\/my-press\/kick-start-react-native-with-basics-stack-navigation\/","title":{"rendered":"Kick Start &#8211; React Native with Basics &#8211; Stack Navigation"},"content":{"rendered":"\n<p style=\"font-size:14px\">We have seen different choices to work on hybrid mobile apps in the previous post, &#8216;<a href=\"http:\/\/www.prasadk.com\/my-press\/hybrid-mobile-apps-react-native-ionic-capacitor-more-to-choose-from\/\">http:\/\/www.prasadk.com\/my-press\/hybrid-mobile-apps-react-native-ionic-capacitor-more-to-choose-from\/<\/a>&#8216;.<\/p>\n\n\n\n<p style=\"font-size:14px\" class=\"has-text-align-left\">More on what is react native, pros, cons, detailed blog posts on React Native here &#8211; <a href=\"https:\/\/www.oreilly.com\/library\/view\/learning-react-native\/9781491929049\/ch01.html\"><br \/><\/a><em><a href=\"https:\/\/www.oreilly.com\/library\/view\/learning-react-native\/9781491929049\/ch01.html\">https:\/\/www.oreilly.com\/library\/view\/learning-react-native\/9781491929049\/ch01.html<\/a><br \/><a href=\"https:\/\/www.weblineindia.com\/blog\/react-native-development-pros-cons\/\">https:\/\/www.weblineindia.com\/blog\/react-native-development-pros-cons\/<\/a><br \/><a href=\"https:\/\/medium.com\/weblineindia\/what-is-react-native-development-advantages-and-disadvantages-e5bf052473a7\">https:\/\/medium.com\/weblineindia\/what-is-react-native-development-advantages-and-disadvantages-e5bf052473a7<\/a>  <\/em><\/p>\n\n\n\n<p style=\"font-size:14px\">Now, let&#8217;s look at some basics of React Native(going forward, I may refer it as &#8211; RN) and kick off our learning RN!<\/p>\n\n\n\n<p style=\"font-size:14px\" class=\"has-text-align-left\">The most frequently asked question &#8211; &#8216;where and how do I get started&#8217;?! <br \/>It depends on person to person and the prior experience, competency in JavaScript etc. I can tell about how I have started it with. <br \/>I did not have any prior knowledge on React. I wanted a quick start but needed to understand the basics. <br \/>I love simple tutorial with hands-on or immediate place where I can try something. So, I went ahead with &#8211; my all time favorite place &#8211; W3Cschools (<a href=\"https:\/\/www.w3schools.com\/react\/\">https:\/\/www.w3schools.com\/react\/<\/a>)<\/p>\n\n\n\n<p style=\"font-size:14px\">After that, you can get started with any basic React Native tutorial or the react documentation itself.<br \/><a href=\"https:\/\/reactnative.dev\/docs\/tutorial\">https:\/\/reactnative.dev\/docs\/tutorial<\/a>. <\/p>\n\n\n\n<p style=\"font-size:14px\">Okay, let&#8217;s move on with the coding part of it. Since, this is not a getting started tutorial or a basic RN tutorial post, I will leave it to get going with whatever you like from RN official docs to get started with. <br \/>This is just a quick introduction on couple of basic topics on recent change.<br \/>Based on my initial learning, I would like to highlight an important change\/update. <br \/>Recently, React Native has changes on usage of react navigation. <br \/>Hope this helps someone looking for a single source of &#8216;how to&#8217; tutorial section on using stack navigator.<\/p>\n\n\n\n<p style=\"font-size:14px\">I have spent almost a day figuring out the recent changes\/updates on this!<br \/>Its already given in the recent react navigation docs, but for me, it was little confusing, as I had referred other React Native courses\/video tutorials which are not upgraded with recent changes!<\/p>\n\n\n\n<p style=\"font-size:14px\">I am not going in depth of what is react navigation etc., but a quick thing on how to navigate between 2 screens using React Native&#8217;s stack navigator with component approach.<\/p>\n\n\n\n<p style=\"font-size:14px\">First step is to install react-navigation &#8211; To use React Native Stack Navigation &#8211; following dependencies to be installed &#8211;<br \/>(note &#8211; I used npm and non-expo managed as I use Android studio with emulator for my testing. If you <br \/> are on expo &#8211; please do check docs and use &#8216;expo&#8217;).<\/p>\n\n\n\n<p style=\"font-size:11px\" class=\"has-text-color has-pink-color\"><code>npm install @react-navigation\/native<br \/>npm install react-native-reanimated react-native-handler react-native-screens react-native-safe-area-context @react-native-community\/masked-view<br \/>npm install @react-navigation\/stack<\/code><\/p>\n\n\n\n<p class=\"has-small-font-size\">Once you are done with the installation, use the following to navigate between screens &#8211;<br \/><code>import { NavigationContainer } from '@react-navigation\/native';<br \/>import { createStackNavigator } from '@reactnavigation\/stack';<\/code><\/p>\n\n\n\n<p style=\"font-size:11px\"><code> const&nbsp;Stack&nbsp;=&nbsp;createStackNavigator(); <br \/>&lt;Stack.Navigator initialRouteName='FruitList' &gt;            &lt;Stack.Screen name='FruitList' component={FruitList} options={{ title: 'Fruits List'}} \/&gt;   <br \/>&lt;Stack.Screen name='FruitDetails' component={FruitDetails} options={{ title: 'Fruits Image'}} \/&gt;        &lt;\/Stack.Navigator&gt; <\/code><\/p>\n\n\n\n<p style=\"font-size:14px\">So, the above code is self-explanatory, if you are already familiar with the react documentation.<\/p>\n\n\n\n<p class=\"has-small-font-size\">From &#8211; <a href=\"https:\/\/reactnavigation.org\/docs\/hello-react-navigation\">https:\/\/reactnavigation.org\/docs\/hello-react-navigation<\/a>, <br \/>Stack.Navigator is a component that takes route configuration as its children with additional props for configuration and renders our content.<br \/>Each Stack.Screen component takes a name prop which refers to the name of the route and component prop which specifies the component to render for the route. These are the 2 required props.<br \/>To specify what the initial route in a stack is, provide an initialRouteName as the prop for the navigator.<br \/>To specify screen-specific options, we can pass an options prop to Stack.Screen, and for common options, we can pass screenOptions to Stack.Navigator.<\/p>\n\n\n\n<p class=\"has-small-font-size\"> Also another recent change to note is old RN cli has been now moved to community\/cli.  So, if you would like to update to latest RN, please uninstall old cli and upgrade to new one as below &#8211;<br \/><code>npm uninstall -g react-native-cli <br \/>npm (or yarn) global add @react-native-community\/ <\/code> <\/p>\n\n\n\n<p style=\"font-size:14px\">Bonus Point -I wanted to use ListItem from react-native-elements, so I have used the following. <br \/> Just posting here as additional item for reference, as installing this too, is not straightforward to get the ListItem working! <\/p>\n\n\n\n<p class=\"has-small-font-size\">React Native Elements &#8211;<br \/><code>npm i react-native-elements --save<br \/>npm i --save react-native-vector-icons<\/code><\/p>\n\n\n\n<p style=\"font-size:14px\">With your learning, you may soon figure it out why did I mention -&#8216;extensively changing, less resources to work on&#8217; etc. in my previous post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have seen different choices to work on hybrid mobile apps in the previous post, &#8216;http:\/\/www.prasadk.com\/my-press\/hybrid-mobile-apps-react-native-ionic-capacitor-more-to-choose-from\/&#8216;. More on what is react native, pros, cons, detailed [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0},"categories":[7,6],"tags":[],"_links":{"self":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/1102"}],"collection":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/comments?post=1102"}],"version-history":[{"count":13,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/1102\/revisions"}],"predecessor-version":[{"id":1116,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/1102\/revisions\/1116"}],"wp:attachment":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/media?parent=1102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/categories?post=1102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/tags?post=1102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}