{"componentChunkName":"component---src-templates-legacy-tutorial-page-js","path":"/oa/tutorials/wthr-native-tutorial-mvs/props-and-weather-data/","result":{"pageContext":{"tutorial":{"id":"T0E6OlR1dG9yaWFsLTE5NA==","slug":"wthr-native-tutorial-mvs","title":"Wthr Native Tutorial","previewText":"Learn the basics of React Native\n","heroImagePath":"https://raw.githubusercontent.com/MakeSchool-Tutorials/FEW-2.4-Wthr-Native-Tutorial/master/cover.png","heroImageFile":{"childImageSharp":{"gatsbyImageData":{"layout":"constrained","placeholder":{"fallback":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAD6ElEQVQ4y42RX0xcRRTGLwu+YKxGk1ZD60N3Gl7qCwoxmmqkaGO0aXzQxNYHHzSxPmliNBqNYrVWU+auRYnWSA1SoYFuNPhQ2vLn3pUWUigiKBQKhYXddZe1bFl22b33zvnMzN1rtm2aOMnkzJw553e+c0YDkZZzRAkAuTVB9AkRrViOiIAoBhRvxIgoZjkiCqKkI8SrMgdA6T9ZSyMi7ToYgE+JCAAhmbVRP7iMdwcSeG8ggZe6w9jdNY83jSiylgMSQsUBeKUYqhXDImkLx/5MOQAJgKh/MUN1wUV65MQ83fbVBG1pnqILsYyqmM7ZzuHQHK6tW9dBNQ+2mnew71TUecuMq7JZy1H2YnwdO0+G8UDrNGaurksXcrYg2cmO7wbFC22jcJRaF6pg0TUL+3v/FjXtC/Th+WX5SN/8kUTH9IoChJbWMJbIqnPrZAq/RTIqZk/rCG6vPy1e7hzD1UxeQSUw8svsKh4+sWDVBRfx/rll1dLBC3GUN02gL5yGt7rm0jIOxpILfPbHYdr8RS/uOnAm1z+XlL5+zXKoGsBqy2QKVT/N2x+ccxXqo8vkaxzH5uZJ9ITT6F7IoC4YxmMdYalQFX2mZRgbPj5tdYxHZc5Mat26vzBDF/r12AreMOK2fG0YSVB50wTdc/QvbG+Zws72GezuiuLxjgVygYQnvh+yjo0syvDLa3m7wpthWeFjqgXR6nBczcoOjC6jtHGcqtrm6KnOK9imm6htn6ba4BINqBkKazCsZnw574iKAqPM+2UFJZJKSQ3t0HDC3tJ8Cc/9GqFdJ+eJcYMqdYOqW6bQv5S1CmOdXcs7FcUMzXEcr23lSGYd1f7P7kfZe7oieLLzClUGTNp6uA/3ft5njcbWlLKpZKbiBkGqZQUVQkiHehDCnem34yvY0RG2nw7Oq5Y3HuyxWkeXFOxazlUmcyRIbqVQLnnxoJ5SOVMA6aMTKdQcn7XvO9TrwWZzDv2nzIMpdcXLgxa3AHKVNo4k8MPFiFKWyORvavMmWDHUtm+Agh4CkAJwKWs5/x92C2iptFlbbF3JWpuKfbeEMW74GDel1Rg3S+T9bApa+Ufd2oYDZ3zHf4+U5QsFmgYXyk5NJ7TKgOlTeYEBmVfq50Ypc7fPA8ntY3rIvQeGpC3xc0Or1E2tvnemTHvwiDpv01WiG/fleWX93p0bUqG5l+mhOxVMD93NuPkiOzJUUii0l3HzUVVQD21k3HzeTTZrGTdeY4GBOxg33mHc+IxxQ5e5khpj3GjzN/TJc5BxI+Jv6JGATYW3s37eL+9V8sy4uY9xY4Rxs4bpoe2MG3N+brzu58bbjBu7/gWOSk/VhPcKJgAAAABJRU5ErkJggg=="},"images":{"fallback":{"src":"/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/5aead/cover.png","srcSet":"/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/e9fba/cover.png 50w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/15e42/cover.png 100w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/5aead/cover.png 200w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/d6138/cover.png 400w","sizes":"(min-width: 200px) 200px, 100vw"},"sources":[{"srcSet":"/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/b79cb/cover.avif 50w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/6d0de/cover.avif 100w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/f2685/cover.avif 200w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/4ff31/cover.avif 400w","type":"image/avif","sizes":"(min-width: 200px) 200px, 100vw"},{"srcSet":"/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/dbc4a/cover.webp 50w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/d8057/cover.webp 100w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/2e34e/cover.webp 200w,\n/mediabook/static/a69ceb219f4e17b4f09e707a84068da8/416c3/cover.webp 400w","type":"image/webp","sizes":"(min-width: 200px) 200px, 100vw"}]},"width":200,"height":200}}},"pages":{"nodes":[{"id":"T0E6OlBhZ2UtMTcxMQ==","title":"Getting Started","slug":"getting-started","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tODM4Nw==","title":"Getting Started","htmlContent":"<p>What's <strong>Wthr</strong>? It's a new native app that shows the current weather info on your phone.</p><p><em>What does it mean to be a native app?</em> As a native app, it runs truly native code on your device.</p><p>Does it work on iOS or Android? It runs on both! This project is built with <strong>React Native</strong>. React Native can build for Android and iOS both from the same code base. React Native is based on React which is a JavaScript library for creating user interfaces. React Native is written with JavaScript using the syntax and patterns used with React but compiles into native iOS or Android code.</p><p>Read more about it <a href=\"https://facebook.github.io/react-native/\" target=\"_blank\">here</a>.</p>"},{"id":"T0E6OlNlY3Rpb24tODM4OA==","title":"Why Is This Important","htmlContent":"<p>Learning this will provide the foundation for the work you'll do through FEW 2.4, where you'll be building more complex react native apps and doing a deeper dive on the fundamentals that you'll learn here.</p>"},{"id":"T0E6OlNlY3Rpb24tODM4OQ==","title":"Prerequisites","htmlContent":"<p>You need to know the basics of JavaScript. If you have experience with React that will help but is not required.</p><p>You do need a computer with a text editor and mobile phone, iOS or Android for testing your project. You can also test from the desktop using the iOS or Android simulator, but this is more work than testing on a real phone. <strong>For this purpose of this tutorial, we will test from a real device.</strong></p>"},{"id":"T0E6OlNlY3Rpb24tODM5MA==","title":"Learning Outcomes","htmlContent":"<p>By the end of this tutorial, students should be able to...</p><ol>\n<li>Use and create React Native Components</li>\n<li>Use Props and State to configure and manage components</li>\n<li>Use Native networking</li>\n</ol>"},{"id":"T0E6OlNlY3Rpb24tODM5MQ==","title":"Technical Planning","htmlContent":"<p>Let's get a good outline going of what we need to do:</p><ol>\n<li>Build out the components of this app</li>\n<li>Implement the lifecycle methods for the Components</li>\n<li>Implement props and load in weather data</li>\n</ol>"},{"id":"T0E6OlNlY3Rpb24tODM5Mg==","title":"Node.JS","htmlContent":"<p>To work with React Native you'll need to install Node.js:</p><div class=\"action\">\n<p></p>\n\n<p>Install Node via this <a href=\"https://nodejs.org/en/download/\" target=\"_blank\">download link</a>, or through a package manager of your choice such as <a href=\"https://brew.sh/\" target=\"_blank\">Homebrew</a></p>\n</div>"},{"id":"T0E6OlNlY3Rpb24tODM5Mw==","title":"Installing Xcode or Android Studio","htmlContent":"<p>If you're building apps for iOS you'll want to install Xcode. This only runs on a Mac. If you want to build apps for Android you'll want to install Android Studio. This runs on either Mac or Windows.</p><div class=\"action\">\n<p></p>\n\n<p>If you're building for iOS, <a href=\"https://itunes.apple.com/us/app/xcode/id497799835?mt=12\" target=\"_blank\">install Xcode here</a> and be sure to install with Command Line Tools as well. If you didn't, you can still install them by following <a href=\"http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/\" target=\"_blank\">these instructions</a></p>\n\n<p>If you're building for Android,  <a href=\"https://developer.android.com/studio/install\" target=\"_blank\">install Android Studio here</a></p>\n</div>"},{"id":"T0E6OlNlY3Rpb24tODM5NA==","title":"Set Up Git/GitHub","htmlContent":"<p>Much like we've done in earlier tutorials, make sure you're committing your code as you complete milestones. At a minimum, you should make a commit whenever the tutorial prompts you.</p><p>Now set up your repo!</p><div class=\"action\">\n<p>\nMake your first commit</p>\n<pre>$ git init\n$ git add .\n$ git commit -m <span class=\"s1\">'project init'</span>\n</pre>\n</div><p>Now Go to GitHub and create a public repository called REPO-NAME, and now associate it as a remote for your local git project and then push to it.</p><div class=\"action\">\n<p>\nPush it!</p>\n<pre>$ git remote add origin GITHUB-REPO-URL\n$ git push origin main -u\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tODM5NQ==","title":"Init with Expo","htmlContent":"<p>Once those are done, let's get our project set up. We're going to be using <a href=\"https://expo.io/learn\" target=\"_blank\">Expo</a> to display our product on our mobile devices.</p><div class=\"action\">\n<p></p>\n\n<p>Open the terminal and install Expo. After that, use Expo to initialize your project. Replace <code>&lt;NameOfProject&gt;</code> with the name of the project you are creating.</p>\n<pre>$ npm install expo-cli --g\n$ expo init &lt;NameOfProject&gt;\n</pre>\n</div><p>Expo will prompt you with a few commands. Provide the following answers:</p><div class=\"action\">\n<p></p>\n\n<p>The command will prompt you for the type of starter project you want to create. <strong>Choose 'Blank template'</strong></p>\n\n<p>Next, the command prompts you for an app name. This can be different from the project name.</p>\n\n<p>Wait for the process to finish installing all of the dependent files.</p>\n</div><p>While those are installing, you'll need to install the Expo Client on your phone before being able to use your app. Expo Client runs in your phone and is used to preview your App while you work.</p><div class=\"action\">\n<p></p>\n\n<p>Install the Expo Client on your phone:</p>\n\n<ul>\n<li><a href=\"https://itunes.apple.com/app/apple-store/id982107779\" target=\"_blank\">iOS app</a></li>\n<li><a href=\"https://play.google.com/store/apps/details?id=host.exp.exponent&amp;referrer=www\" target=\"_blank\">Android</a></li>\n</ul>\n\n<p>Sign up for an account in the app in order to use it.</p>\n</div><p>After all the dependencies are installed, follow the prompts at the end:</p><div class=\"action\">\n<p></p>\n\n<p>Run the following commands, replacing <code>&lt;NameOfProject&gt;</code> with your project name:</p>\n<pre>$ <span class=\"nb\">cd</span> &lt;NameOfProject&gt;\n$ npm start\n</pre>\n</div><p>This should open a browser window which looks something like:</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/FEW-2.4-Wthr-Native-Tutorial@472a97a89c9e284cc006a5c6eeedef2144711fb0/P00-Getting-Started/assets/01_init-with-expo_expo-page.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/FEW-2.4-Wthr-Native-Tutorial@472a97a89c9e284cc006a5c6eeedef2144711fb0/P00-Getting-Started/assets/01_init-with-expo_expo-page.png\" alt=\"ScreenShot-1.png\" title=\"\">\n        </a></p><div class=\"action\">\n<p></p>\n\n<p>Scan the QR code in the lower left with your phone.</p>\n\n<p>On the iPhone you can open the camera and scan the image, you don't need to take a picture. The phone should open a notification asking if you want to open Expo.</p>\n</div><p>You should be up and ready to go now. Let's write some code!</p>"},{"id":"T0E6OlNlY3Rpb24tODM5Ng==","title":"Now Commit","htmlContent":"<div class=\"action\">\n<p></p>\n<pre>$ git add .\n$ git commit -m <span class=\"s1\">'project init'</span>\n$ git push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMTcxMg==","slug":"react-and-react-native-basic-concepts","title":"React and React Native Basic concepts "},"previous":{"id":"T0E6OlBhZ2UtMTcxMg==","slug":"react-and-react-native-basic-concepts","title":"React and React Native Basic concepts "}},{"id":"T0E6OlBhZ2UtMTcxMg==","title":"React and React Native Basic concepts ","slug":"react-and-react-native-basic-concepts","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tNzkxNg==","title":"React and React Native Basic concepts ","htmlContent":"<ol>\n<li>\n<strong>Build out the components of this app</strong>\n\n<ol>\n<li><strong>Get basic, stubbed out components set up</strong></li>\n<li><strong>Add some style to them</strong></li>\n</ol>\n</li>\n<li>Implement the lifecycle methods for the Components</li>\n<li>Implement props and load in weather data</li>\n</ol><p>Let's go over some building blocks of React and React Native that we will use to create our Wthr app.</p>"},{"id":"T0E6OlNlY3Rpb24tNzkxNw==","title":"Components","htmlContent":"<p>React projects are written in JavaScript. The basic building block in React is the Component. <strong>Components</strong> are usually things you can see on the screen and may also have some business logic code that manages their behavior.</p><p>Components can be written as a function or as a class that extends <code>React.Component</code>.</p><p>Look at <code>App.js</code> in your project. This file in the entry point. It's also the top level component. Think of components like a tree: one component can branches/child components and these can have their own children. <code>App.js</code> is like the root of the tree.</p><div class=\"action\">\n<p></p>\n\n<p>Review <code>App.js</code> below and make sure you understand what's going on:</p>\n<pre><span class=\"c1\">// This imports React from the 'react' package</span>\n<span class=\"kr\">import</span> <span class=\"nx\">React</span> <span class=\"nx\">from</span> <span class=\"s1\">'react'</span><span class=\"p\">;</span>\n<span class=\"c1\">// This imports two native Components: `Text`, and `View` from the 'react-native' package.</span>\n<span class=\"c1\">// `StyleSheet` is a helper Object for creating styles sheets in React Native.  </span>\n<span class=\"kr\">import</span> <span class=\"p\">{</span> <span class=\"nx\">StyleSheet</span><span class=\"p\">,</span> <span class=\"nx\">Text</span><span class=\"p\">,</span> <span class=\"nx\">View</span> <span class=\"p\">}</span> <span class=\"nx\">from</span> <span class=\"s1\">'react-native'</span><span class=\"p\">;</span>\n\n<span class=\"c1\">// The next block of code is the definition of a component. This component is named App, and it extends `React.Component`.</span>\n<span class=\"c1\">// Components that extend `React.Component` must implement a render function. The `render()` method must return JSX.</span>\n<span class=\"kr\">export</span> <span class=\"k\">default</span> <span class=\"kr\">class</span> <span class=\"nx\">App</span> <span class=\"kr\">extends</span> <span class=\"nx\">React</span><span class=\"p\">.</span><span class=\"nx\">Component</span> <span class=\"p\">{</span>\n  <span class=\"nx\">render</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n    <span class=\"c1\">// JSX is an extension of the JavaScript language. It allows you to write code that looks like HTML/XML within your JavaScript.</span>\n    <span class=\"k\">return</span> <span class=\"p\">(</span>\n      <span class=\"c1\">// This is a View component with a child Text component. These are displayed on the screen in the default app. Remember these were imported above.</span>\n      <span class=\"o\">&lt;</span><span class=\"nx\">View</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">container</span><span class=\"p\">}</span><span class=\"o\">&gt;</span>\n        <span class=\"o\">&lt;</span><span class=\"nx\">Text</span><span class=\"o\">&gt;</span><span class=\"nx\">Open</span> <span class=\"nx\">up</span> <span class=\"nx\">App</span><span class=\"p\">.</span><span class=\"nx\">js</span> <span class=\"nx\">to</span> <span class=\"nx\">start</span> <span class=\"nx\">working</span> <span class=\"nx\">on</span> <span class=\"nx\">your</span> <span class=\"nx\">app</span><span class=\"o\">!&lt;</span><span class=\"err\">/Text&gt;</span>\n      <span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n    <span class=\"p\">);</span>\n  <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n\n<span class=\"c1\">// This defines an object that will be used to style the components here in the app component.</span>\n<span class=\"kr\">const</span> <span class=\"nx\">styles</span> <span class=\"o\">=</span> <span class=\"nx\">StyleSheet</span><span class=\"p\">.</span><span class=\"nx\">create</span><span class=\"p\">({</span>\n  <span class=\"c1\">// These properties of `container` are standard CSS properties, and the values are the same values you would have used in CSS.</span>\n  <span class=\"nx\">container</span><span class=\"o\">:</span> <span class=\"p\">{</span>\n    <span class=\"nx\">flex</span><span class=\"o\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n    <span class=\"nx\">backgroundColor</span><span class=\"o\">:</span> <span class=\"s1\">'#fff'</span><span class=\"p\">,</span>\n    <span class=\"nx\">alignItems</span><span class=\"o\">:</span> <span class=\"s1\">'center'</span><span class=\"p\">,</span>\n    <span class=\"nx\">justifyContent</span><span class=\"o\">:</span> <span class=\"s1\">'center'</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n<span class=\"p\">});</span>\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkxOA==","title":"Native Components","htmlContent":"<p>React Native uses native components. So far we've seen the <code>View</code> and <code>Text</code> Components, let's cover those in a bit more detail:</p><h2>Text</h2><p>Makes text</p><p><code>&lt;Text&gt;Some text that is displayed...&lt;/Text&gt;</code></p><h2>View</h2><p>A view is a rectangular area on the screen that can display child elements.</p><pre><span class=\"p\">&lt;</span><span class=\"n\">View</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">...</span><span class=\"n\">Child</span> <span class=\"n\">Components</span><span class=\"p\">...</span>\n<span class=\"o\">&lt;/</span><span class=\"n\">View</span><span class=\"p\">&gt;</span>\n</pre><h2>Styling Components</h2><p>React native supports a subset of CSS style properties and units.</p><p>Typically you'll set all styles \"inline\" on each element and define them as a JS Object.</p><p><code>&lt;View style={{backgroundColor:'#f00'}}&gt;&lt;/View&gt;</code></p>"},{"id":"T0E6OlNlY3Rpb24tNzkxOQ==","title":"Define Your Own Component","htmlContent":"<p>Let's define a component that displays the Weather Data:</p><div class=\"action\">\n<p></p>\n\n<p>Create a new file named <code>DisplayWeather.js</code>. Make a folder in your project named: <code>Components</code> save this file there.</p>\n\n<p>Add the following to <code>DisplayWeather.js</code>:</p>\n<pre><span class=\"kr\">import</span> <span class=\"nx\">React</span> <span class=\"nx\">from</span> <span class=\"s1\">'react'</span>\n<span class=\"kr\">import</span> <span class=\"p\">{</span> <span class=\"nx\">Text</span><span class=\"p\">,</span> <span class=\"nx\">View</span><span class=\"p\">,</span> <span class=\"nx\">StyleSheet</span> <span class=\"p\">}</span> <span class=\"nx\">from</span> <span class=\"s1\">'react-native'</span>\n\n<span class=\"kr\">const</span> <span class=\"nx\">DisplayWeather</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n  <span class=\"k\">return</span> <span class=\"p\">(</span>\n      <span class=\"o\">&lt;</span><span class=\"nx\">View</span><span class=\"o\">&gt;</span>\n        <span class=\"o\">&lt;</span><span class=\"nx\">Text</span><span class=\"o\">&gt;</span><span class=\"mi\">72</span><span class=\"err\">&#730;</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n      <span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n  <span class=\"p\">)</span>\n<span class=\"p\">}</span>\n\n<span class=\"kr\">export</span> <span class=\"k\">default</span> <span class=\"nx\">DisplayWeather</span>\n</pre>\n</div><p>This defines a simple component. <em>This component is defined as a function.</em> Component function based component must return JSX and should take a single parameter named props. The View component will act as a container for the Text, and the Text will display the temperature.</p><p>For now, we will assume the temperature is 72&#730;. In the future, you will get the weather data from an online service and display the actual temperature here.</p><p>Lastly, let's add a style sheet. Do this by defining a variable named <code>styles</code> and assigning it an Object with CSS properties that can be applied to Components.</p><div class=\"action\">\n<p></p>\n\n<p>Add a StyleSheet to <code>/Components/DisplayWeather.js</code>:</p>\n<pre><span class=\"kr\">import</span> <span class=\"nx\">React</span> <span class=\"nx\">from</span> <span class=\"s1\">'react'</span>\n<span class=\"kr\">import</span> <span class=\"p\">{</span> <span class=\"nx\">Text</span><span class=\"p\">,</span> <span class=\"nx\">View</span><span class=\"p\">,</span> <span class=\"nx\">StyleSheet</span> <span class=\"p\">}</span> <span class=\"nx\">from</span> <span class=\"s1\">'react-native'</span>\n\n<span class=\"kr\">const</span> <span class=\"nx\">DisplayWeather</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n  <span class=\"k\">return</span> <span class=\"p\">(</span>\n    <span class=\"o\">&lt;</span><span class=\"nx\">View</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">container</span><span class=\"p\">}</span><span class=\"o\">&gt;</span>\n      <span class=\"o\">&lt;</span><span class=\"nx\">Text</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">temp</span><span class=\"p\">}</span><span class=\"o\">&gt;</span><span class=\"mi\">72</span><span class=\"err\">&#730;</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n    <span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n  <span class=\"p\">)</span>\n<span class=\"p\">}</span>\n\n<span class=\"kr\">export</span> <span class=\"k\">default</span> <span class=\"nx\">DisplayWeather</span>\n\n<span class=\"c1\">// These objects are assigned to the `style` prop on each of the two components.</span>\n<span class=\"kr\">const</span> <span class=\"nx\">styles</span> <span class=\"o\">=</span> <span class=\"nx\">StyleSheet</span><span class=\"p\">.</span><span class=\"nx\">create</span><span class=\"p\">({</span>\n  <span class=\"nx\">container</span><span class=\"o\">:</span> <span class=\"p\">{</span>\n    <span class=\"nx\">flex</span><span class=\"o\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n    <span class=\"nx\">justifyContent</span><span class=\"o\">:</span> <span class=\"s1\">'center'</span>\n  <span class=\"p\">},</span>\n  <span class=\"nx\">temp</span><span class=\"o\">:</span> <span class=\"p\">{</span>\n    <span class=\"nx\">fontSize</span><span class=\"o\">:</span> <span class=\"mi\">40</span><span class=\"p\">,</span>\n    <span class=\"nx\">fontWeight</span><span class=\"o\">:</span> <span class=\"s1\">'bold'</span>\n  <span class=\"p\">}</span>\n<span class=\"p\">})</span>\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkyMA==","title":"Test your Component","htmlContent":"<p>Now that we have a component, let's import and display it in the app:</p><div class=\"action\">\n<p></p>\n\n<p>Add the following at the top of <code>App.js</code>.</p>\n<pre><span class=\"kr\">import</span> <span class=\"nx\">DisplayWeather</span> <span class=\"nx\">from</span> <span class=\"s1\">'./Components/DisplayWeather'</span>\n</pre>\n</div><p>Notice, when importing your own files you'll need to include a path. Since the file is in the same folder the path begins: './'</p><div class=\"action\">\n<p></p>\n\n<p>Replce the current component in the <code>render()</code> method of <code>App.js</code> with your component:</p>\n<pre><span class=\"o\">&lt;</span><span class=\"nx\">View</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">container</span><span class=\"p\">}</span><span class=\"o\">&gt;</span>\n  <span class=\"o\">&lt;</span><span class=\"nx\">DisplayWeather</span> <span class=\"o\">/&gt;</span>\n<span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkyMQ==","title":"Product So Far","htmlContent":"<p>Notice that you don't need to use a closing tag for <code>DisplayWeather</code> since it doesn't have any children. You do need to use /&gt; to 'self-close' this tag.</p><p>Try loading the app on your phone, you should see it say 72&#730; in the center of the screen.</p><p>Congrats! You got some great practice with <strong>using and creating React Native Components!</strong></p>"},{"id":"T0E6OlNlY3Rpb24tNzkyMg==","title":"Now Commit","htmlContent":"<div class=\"action\">\n<p></p>\n<pre>$ git add .\n$ git commit -m <span class=\"s1\">'added displayweather component'</span>\n$ git push\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkyMw==","title":"Stretch Challenge:","htmlContent":"<div class=\"challenge\">\n<p></p>\n\n<p>Add another Text component to display a description of the weather. Edit the Display Weather component. Add another Text component below the Temp. Use some text that describes the weather, something like:</p>\n\n<p>Partly Cloudy</p>\n\n<p>Save and test your work. Your app should refresh its view in Expo.</p>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMTcxMw==","slug":"component-lifecycle","title":"Component Lifecycle"},"previous":{"id":"T0E6OlBhZ2UtMTcxMw==","slug":"component-lifecycle","title":"Component Lifecycle"}},{"id":"T0E6OlBhZ2UtMTcxMw==","title":"Component Lifecycle","slug":"component-lifecycle","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tNzkyNA==","title":"Component Lifecycle","htmlContent":"<ol>\n<li><del>Build out the components of this app</del></li>\n<li>\n<strong>Implement the lifecycle methods for the Components</strong>\n\n<ol>\n<li><strong>Implement the <code>componentDidMount</code> method</strong></li>\n<li><strong>Implement State in the app</strong></li>\n<li><strong>Fetch the weather data</strong></li>\n</ol>\n</li>\n<li>Implement props and load in weather data</li>\n</ol><p>Components have a lifecycle that can be used to track when they are created and when they are removed. We would like the App Component to get the geolocation when the component is created.</p><p>To get the weather data, we need to know the location of the phone. We can get this:</p><p><code>navigator.geolocation.getCurrentPosition(success, error, options)</code></p><p>The component needs to know if the location data is available or not. Getting location data is an asynchronous operation. You'll need to make a request and wait for a response.</p>"},{"id":"T0E6OlNlY3Rpb24tNzkyNQ==","title":"Component Lifecycle methods","htmlContent":"<p>The <code>componentDidMount()</code> method is called when the component is created and added to a view. The code in this method will run at that time. The code here requests the current position. If the request is successful it prints the data to the console if not it prints an error.</p><div class=\"action\">\n<p></p>\n\n<p>To get geolocation, add the <code>componentDidMount()</code> method to <code>App.js</code>:</p>\n<pre><span class=\"kr\">export</span> <span class=\"k\">default</span> <span class=\"kr\">class</span> <span class=\"nx\">App</span> <span class=\"kr\">extends</span> <span class=\"nx\">React</span><span class=\"p\">.</span><span class=\"nx\">Component</span> <span class=\"p\">{</span>\n\n  <span class=\"nx\">componentDidMount</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n    <span class=\"nx\">navigator</span><span class=\"p\">.</span><span class=\"nx\">geolocation</span><span class=\"p\">.</span><span class=\"nx\">getCurrentPosition</span><span class=\"p\">((</span><span class=\"nx\">location</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n      <span class=\"nx\">console</span><span class=\"p\">.</span><span class=\"nx\">log</span><span class=\"p\">(</span><span class=\"nx\">location</span><span class=\"p\">)</span>\n    <span class=\"p\">},</span> <span class=\"p\">(</span><span class=\"nx\">err</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n      <span class=\"nx\">console</span><span class=\"p\">.</span><span class=\"nx\">log</span><span class=\"p\">(</span><span class=\"nx\">err</span><span class=\"p\">.</span><span class=\"nx\">message</span><span class=\"p\">)</span>\n    <span class=\"p\">})</span>\n  <span class=\"p\">}</span>\n\n  <span class=\"nx\">render</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n    <span class=\"k\">return</span> <span class=\"p\">(</span>\n      <span class=\"o\">&lt;</span><span class=\"nx\">View</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">container</span><span class=\"p\">}</span><span class=\"o\">&gt;</span>\n        <span class=\"o\">&lt;</span><span class=\"nx\">DisplayWeather</span> <span class=\"o\">/&gt;</span>\n      <span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n    <span class=\"p\">);</span>\n  <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n\n<span class=\"p\">...</span>\n</pre>\n</div><p>Running the code now will cause Expo to refresh your and the phone will ask you for permission to use your location. Tapping Allow will show the following in the console where you ran <code>npm start</code> a moment later:</p><pre><span class=\"err\">Object</span> <span class=\"p\">{</span>\n  <span class=\"nt\">\"coords\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"accuracy\"</span><span class=\"p\">:</span> <span class=\"mi\">65</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"altitude\"</span><span class=\"p\">:</span> <span class=\"mf\">34.92243192580078</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"altitudeAccuracy\"</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"heading\"</span><span class=\"p\">:</span> <span class=\"mi\">-1</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"latitude\"</span><span class=\"p\">:</span> <span class=\"mf\">37.75495136832096</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"longitude\"</span><span class=\"p\">:</span> <span class=\"mf\">-122.49818570206919</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"speed\"</span><span class=\"p\">:</span> <span class=\"mi\">-1</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"timestamp\"</span><span class=\"p\">:</span> <span class=\"mf\">1552707836378.427</span><span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</pre><p><strong>NOTE:</strong> You may need to restart the expo app and re-scan the QR code to see the above output.</p>"},{"id":"T0E6OlNlY3Rpb24tNzkyNg==","title":"State","htmlContent":"<p>Your component needs to know when it has geolocation and when it doesn't. It won't have the data when loads, and it may never get the data if it isn't allowed access to the phone's location or if the data isn't available for some other reason.</p><p>You can use <code>state</code> to keep track of this. <code>state</code> is a feature of Class-based components, and setting <code>state</code> will cause a component to render. This means that changing <code>state</code> will allow your component to redraw itself!</p><div class=\"action\">\n<p></p>\n\n<p>Define some state by adding a constructor to <code>App.js</code> within the class definition:</p>\n<pre><span class=\"kr\">export</span> <span class=\"k\">default</span> <span class=\"kr\">class</span> <span class=\"nx\">App</span> <span class=\"kr\">extends</span> <span class=\"nx\">React</span><span class=\"p\">.</span><span class=\"nx\">Component</span> <span class=\"p\">{</span>\n\n<span class=\"p\">...</span>\n\n<span class=\"nx\">constructor</span><span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n  <span class=\"kr\">super</span><span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">)</span>\n\n  <span class=\"c1\">// These will hold the user's location and the weather data when it is loaded</span>\n  <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"nx\">state</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"nx\">location</span><span class=\"o\">:</span> <span class=\"kc\">null</span><span class=\"p\">,</span>\n    <span class=\"nx\">weather</span><span class=\"o\">:</span> <span class=\"kc\">null</span>\n  <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n\n<span class=\"p\">...</span>\n\n<span class=\"p\">}</span>\n</pre>\n</div><p>Next, we need to set the value of the location state in <code>componentDidMount</code>:</p><div class=\"action\">\n<p></p>\n\n<p>Update <code>componentDidMount</code> in <code>App.js</code> to the following:</p>\n<pre><span class=\"nx\">componentDidMount</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n  <span class=\"nx\">navigator</span><span class=\"p\">.</span><span class=\"nx\">geolocation</span><span class=\"p\">.</span><span class=\"nx\">getCurrentPosition</span><span class=\"p\">((</span><span class=\"nx\">location</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n    <span class=\"c1\">// Now we're setting the state instead of just logging to console</span>\n    <span class=\"c1\">// You'll always set state by calling `this.setState()`.</span>\n    <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"nx\">setState</span><span class=\"p\">({</span> <span class=\"nx\">location</span> <span class=\"p\">})</span>\n  <span class=\"p\">},</span> <span class=\"p\">(</span><span class=\"nx\">err</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n    <span class=\"nx\">console</span><span class=\"p\">.</span><span class=\"nx\">log</span><span class=\"p\">(</span><span class=\"nx\">err</span><span class=\"p\">.</span><span class=\"nx\">message</span><span class=\"p\">)</span>\n  <span class=\"p\">})</span>\n<span class=\"p\">}</span>\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkyNw==","title":"Loading the Weather data","htmlContent":"<p>Let's get some weather data to load. We'll get ours from <a href=\"openweathermap.org\" target=\"_blank\">openweathermap.org</a>.</p><div class=\"action\">\n<p></p>\n\n<p>Go to <a href=\"openweathermap.org\" target=\"_blank\">openweathermap.org</a> now and make a user account.</p>\n\n<p>Once you've signed in, select <strong>API Keys</strong> from the nav bar, and <strong>copy your developer API key.</strong></p>\n</div><p>React Native uses native systems to get geolocation and to make network requests. These have all been mapped to a JavaScript API that works just like it does in the browser.</p><p>Before we dive into <em>using</em> our brand new API Key. We need to make sure we're storing it safely in our app. We don't want to just hard-code it since that means when we push it to GitHub, it's out for anyone to use! Let's safeguard this now using an <code>.env</code> file, where we can store our private info (such as API Keys) and not have them get uploaded to GitHub or hard-coded in our <code>.js</code> files.</p><p>First thing we need to do is install <a href=\"https://github.com/zetachang/react-native-dotenv\" target=\"_blank\">react-native-dotenv</a>, which lets you import environment variables from a <code>.env</code> file.</p><div class=\"action\">\n<p></p>\n\n<p>Follow the install instructions on the <a href=\"https://github.com/zetachang/react-native-dotenv\" target=\"_blank\">react-native-dotenv GitHub page</a></p>\n\n<p><strong>NOTE:</strong> Your project currently does not have a .<code>babelrc</code> file as the page mentions. Here's a <code>.babelrc</code> example that should match what the <code>react-native-dotenv</code> page is requesting:</p>\n<pre><span class=\"p\">{</span>\n    <span class=\"nt\">\"presets\"</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n        <span class=\"s2\">\"module:metro-react-native-babel-preset\"</span><span class=\"p\">,</span>\n        <span class=\"s2\">\"module:react-native-dotenv\"</span>\n    <span class=\"p\">]</span>\n<span class=\"p\">}</span>\n</pre>\n</div><p><strong>IMPORTANT NOTE:</strong> Make sure your <code>.gitignore</code> is set up to properly ignore <code>.env</code> files.</p><p>Let's create our <code>.env</code> file now:</p><div class=\"action\">\n<p></p>\n\n<p>At the top level of your project directory, create a new <code>.env</code> file, replacing <code>your_api_key</code> with your actual key (no quotes):</p>\n<pre><span class=\"n\">WEATHER_API_KEY</span><span class=\"p\">=</span><span class=\"n\">your_api_key</span>\n</pre>\n</div><p>Now we can actually add a new method to the App Class that will load in our weather data:</p><div class=\"action\">\n<p></p>\n\n<p>Create the <code>loadWeather</code> method in the App Class of <code>App.js</code>, remembering to import our <code>WEATHER_API_KEY</code> at the top of the file:</p>\n<pre><span class=\"kr\">import</span> <span class=\"p\">{</span> <span class=\"nx\">WEATHER_API_KEY</span> <span class=\"p\">}</span> <span class=\"nx\">from</span> <span class=\"s1\">'react-native-dotenv'</span>\n\n<span class=\"kr\">export</span> <span class=\"k\">default</span> <span class=\"kr\">class</span> <span class=\"nx\">App</span> <span class=\"kr\">extends</span> <span class=\"nx\">React</span><span class=\"p\">.</span><span class=\"nx\">Component</span> <span class=\"p\">{</span>\n\n<span class=\"p\">...</span>\n\n<span class=\"nx\">loadWeather</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n  <span class=\"kr\">const</span> <span class=\"nx\">apikey</span> <span class=\"o\">=</span> <span class=\"nx\">WEATHER_API_KEY</span>\n  <span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">latitude</span><span class=\"p\">,</span> <span class=\"nx\">longitude</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"nx\">state</span><span class=\"p\">.</span><span class=\"nx\">location</span><span class=\"p\">.</span><span class=\"nx\">coords</span>\n  <span class=\"kr\">const</span> <span class=\"nx\">units</span> <span class=\"o\">=</span> <span class=\"s1\">'Imperial'</span>\n  <span class=\"kr\">const</span> <span class=\"nx\">url</span> <span class=\"o\">=</span> <span class=\"sb\">`https://api.openweathermap.org/data/2.5/weather?lat=</span><span class=\"si\">${</span><span class=\"nx\">latitude</span><span class=\"si\">}</span><span class=\"sb\">&amp;lon=</span><span class=\"si\">${</span><span class=\"nx\">longitude</span><span class=\"si\">}</span><span class=\"sb\">&amp;appid=</span><span class=\"si\">${</span><span class=\"nx\">apikey</span><span class=\"si\">}</span><span class=\"sb\">&amp;units=</span><span class=\"si\">${</span><span class=\"nx\">units</span><span class=\"si\">}</span><span class=\"sb\">`</span>\n  <span class=\"c1\">// `fetch()` is used to load data</span>\n  <span class=\"nx\">fetch</span><span class=\"p\">(</span><span class=\"nx\">url</span><span class=\"p\">)</span>\n  <span class=\"c1\">// After a connection is made the data is streamed as JSON</span>\n  <span class=\"p\">.</span><span class=\"nx\">then</span><span class=\"p\">(</span><span class=\"nx\">res</span> <span class=\"p\">=&gt;</span> <span class=\"nx\">res</span><span class=\"p\">.</span><span class=\"nx\">json</span><span class=\"p\">())</span>\n  <span class=\"c1\">// When that resolves we use `this.setState()` to assign the weather data to state which will also re-render the component.</span>\n  <span class=\"p\">.</span><span class=\"nx\">then</span><span class=\"p\">(</span><span class=\"nx\">json</span> <span class=\"p\">=&gt;</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"nx\">setState</span><span class=\"p\">({</span> <span class=\"nx\">weather</span><span class=\"o\">:</span> <span class=\"nx\">json</span> <span class=\"p\">}))</span>\n  <span class=\"p\">.</span><span class=\"k\">catch</span><span class=\"p\">(</span><span class=\"nx\">err</span> <span class=\"p\">=&gt;</span> <span class=\"nx\">console</span><span class=\"p\">.</span><span class=\"nx\">log</span><span class=\"p\">(</span><span class=\"nx\">err</span><span class=\"p\">.</span><span class=\"nx\">message</span><span class=\"p\">))</span>\n<span class=\"p\">}</span>\n\n<span class=\"p\">...</span>\n\n<span class=\"p\">}</span>\n</pre>\n</div><p>Call this method when you resolve the location in <code>componentDidMount</code>.</p><div class=\"action\">\n<p></p>\n\n<p>Update <code>componentDidMount</code> to call <code>loadWeather</code>:</p>\n<pre><span class=\"nx\">componentDidMount</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n  <span class=\"nx\">navigator</span><span class=\"p\">.</span><span class=\"nx\">geolocation</span><span class=\"p\">.</span><span class=\"nx\">getCurrentPosition</span><span class=\"p\">((</span><span class=\"nx\">location</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n    <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"nx\">setState</span><span class=\"p\">({</span> <span class=\"nx\">location</span> <span class=\"p\">})</span>\n    <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"nx\">loadWeather</span><span class=\"p\">()</span>\n  <span class=\"p\">},</span> <span class=\"p\">(</span><span class=\"nx\">err</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n    <span class=\"nx\">console</span><span class=\"p\">.</span><span class=\"nx\">log</span><span class=\"p\">(</span><span class=\"nx\">err</span><span class=\"p\">.</span><span class=\"nx\">message</span><span class=\"p\">)</span>\n  <span class=\"p\">})</span>\n<span class=\"p\">}</span>\n</pre>\n</div><p>Great work on <strong>using State to configure and manage components, as well as using some native networking!</strong> We shouldn't see anything change in the app quite yet. We still have some work to do in terms of passing the data from <code>App</code> to <code>DisplayWeather</code>, which we'll get to in the next chapter.</p>"},{"id":"T0E6OlNlY3Rpb24tNzkyOA==","title":"Now Commit","htmlContent":"<div class=\"action\">\n<p></p>\n<pre>$ git add .\n$ git commit -m <span class=\"s1\">'implemented state and component lifecycle'</span>\n$ git push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMTcxNA==","slug":"props-and-weather-data","title":"Props and Weather Data"},"previous":{"id":"T0E6OlBhZ2UtMTcxNA==","slug":"props-and-weather-data","title":"Props and Weather Data"}},{"id":"T0E6OlBhZ2UtMTcxNA==","title":"Props and Weather Data","slug":"props-and-weather-data","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tNzkyOQ==","title":"Props and Weather Data","htmlContent":"<ol>\n<li><del>Build out the components of this app</del></li>\n<li><del>Implement the lifecycle methods for the Components</del></li>\n<li>\n<strong>Implement props and load in weather data</strong>\n\n<ol>\n<li><strong>Pass and use props to send information amongst components</strong></li>\n<li><strong>Load the weather data into the components</strong></li>\n</ol>\n</li>\n</ol><p>Before our app will actually display the weather data, we need to pass the weather data from App to DisplayWeather. Components all have a special property named <strong>props</strong> that are used for passing information from a parent component to a child component.</p>"},{"id":"T0E6OlNlY3Rpb24tNzkzMA==","title":"Passing Props","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Use props to pass the weather data from App to DisplayWeather in <code>App.js</code>:</p>\n<pre><span class=\"nx\">render</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n  <span class=\"k\">return</span> <span class=\"p\">(</span>\n    <span class=\"o\">&lt;</span><span class=\"nx\">View</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">container</span><span class=\"p\">}</span><span class=\"o\">&gt;</span>\n<strong>      <span class=\"o\">&lt;</span><span class=\"nx\">DisplayWeather</span> <span class=\"nx\">data</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"k\">this</span><span class=\"p\">.</span><span class=\"nx\">state</span><span class=\"p\">.</span><span class=\"nx\">weather</span><span class=\"p\">}</span> <span class=\"o\">/&gt;</span>\n</strong>\n    <span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n  <span class=\"p\">);</span>\n<span class=\"p\">}</span></pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkzMQ==","title":"Using Props","htmlContent":"<p>Props are used to passed data from a parent to a child component. Children get values from <strong>keys</strong> on the props object.</p><p>We want the <code>DisplayWeather</code> component to display a message when the weather data is loading. It also needs to display an error message if there was a problem, and otherwise display the weather data.</p><p>In the App component you set your data on the <strong>data prop</strong>. In <code>DisplayWeather</code> you get this as <code>props.data</code>, which we'll use to help us check the above conditions.</p><div class=\"action\">\n<p></p>\n\n<p>Add these two if statements above <code>return</code> in <code>/Components/DisplayWeather.js</code>:</p>\n<pre><span class=\"kr\">const</span> <span class=\"nx\">DisplayWeather</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n  <span class=\"c1\">// No data yet, so it must still be loading</span>\n  <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span> <span class=\"o\">===</span> <span class=\"kc\">null</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"k\">return</span> <span class=\"o\">&lt;</span><span class=\"nx\">Text</span><span class=\"o\">&gt;</span><span class=\"nx\">Loading</span><span class=\"p\">...</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n  <span class=\"p\">}</span>\n\n  <span class=\"c1\">// Cod is where codes go, so if an error occurred, the value would not be 200 (could be 400, 404, etc.)</span>\n  <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">cod</span> <span class=\"o\">!==</span> <span class=\"mi\">200</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"k\">return</span> <span class=\"o\">&lt;</span><span class=\"nx\">Text</span><span class=\"o\">&gt;</span><span class=\"nx\">An</span> <span class=\"nb\">Error</span> <span class=\"nx\">has</span> <span class=\"nx\">occurred</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n  <span class=\"p\">}</span>\n\n  <span class=\"c1\">// If no error and not loading, load/display weather data, grabbing the appropriate data from props</span>\n  <span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">temp</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">main</span>\n  <span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">description</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">weather</span><span class=\"p\">[</span><span class=\"mi\">0</span><span class=\"p\">]</span>\n\n  <span class=\"k\">return</span> <span class=\"p\">(</span>\n    <span class=\"o\">&lt;</span><span class=\"nx\">View</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">container</span><span class=\"p\">}</span><span class=\"o\">&gt;</span>\n      <span class=\"o\">&lt;</span><span class=\"nx\">Text</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">temp</span><span class=\"p\">}</span><span class=\"o\">&gt;</span><span class=\"p\">{</span><span class=\"nx\">temp</span><span class=\"p\">}</span><span class=\"err\">&#730;</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n      <span class=\"o\">&lt;</span><span class=\"nx\">Text</span><span class=\"o\">&gt;</span><span class=\"p\">{</span><span class=\"nx\">description</span><span class=\"p\">}</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n    <span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n  <span class=\"p\">)</span>\n<span class=\"p\">}</span>\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkzMg==","title":"Looking at the OpenWeatherMap Data","htmlContent":"<p>The weather data from OpenWeatherMap is a JSON object. It has a structure. To get information like the temperature and description you'll need to navigate the structure:</p><pre><span class=\"err\">Object</span> <span class=\"p\">{</span>\n  <span class=\"nt\">\"base\"</span><span class=\"p\">:</span> <span class=\"s2\">\"stations\"</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"clouds\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"all\"</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"cod\"</span><span class=\"p\">:</span> <span class=\"mi\">200</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"coord\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"lat\"</span><span class=\"p\">:</span> <span class=\"mf\">37.75</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"lon\"</span><span class=\"p\">:</span> <span class=\"mf\">-122.5</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"dt\"</span><span class=\"p\">:</span> <span class=\"mi\">1552710644</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"id\"</span><span class=\"p\">:</span> <span class=\"mi\">5391997</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"main\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"humidity\"</span><span class=\"p\">:</span> <span class=\"mi\">50</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"pressure\"</span><span class=\"p\">:</span> <span class=\"mi\">1021</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"temp\"</span><span class=\"p\">:</span> <span class=\"mf\">54.36</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"temp_max\"</span><span class=\"p\">:</span> <span class=\"mi\">59</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"temp_min\"</span><span class=\"p\">:</span> <span class=\"mi\">50</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"name\"</span><span class=\"p\">:</span> <span class=\"s2\">\"San Francisco County\"</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"sys\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"country\"</span><span class=\"p\">:</span> <span class=\"s2\">\"US\"</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"id\"</span><span class=\"p\">:</span> <span class=\"mi\">4322</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"message\"</span><span class=\"p\">:</span> <span class=\"mf\">0.0097</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"sunrise\"</span><span class=\"p\">:</span> <span class=\"mi\">1552745967</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"sunset\"</span><span class=\"p\">:</span> <span class=\"mi\">1552789093</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"type\"</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"visibility\"</span><span class=\"p\">:</span> <span class=\"mi\">16093</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"weather\"</span><span class=\"p\">:</span> <span class=\"err\">Array</span> <span class=\"p\">[</span>\n    <span class=\"err\">Object</span> <span class=\"p\">{</span>\n      <span class=\"nt\">\"description\"</span><span class=\"p\">:</span> <span class=\"s2\">\"clear sky\"</span><span class=\"p\">,</span>\n      <span class=\"nt\">\"icon\"</span><span class=\"p\">:</span> <span class=\"s2\">\"01n\"</span><span class=\"p\">,</span>\n      <span class=\"nt\">\"id\"</span><span class=\"p\">:</span> <span class=\"mi\">800</span><span class=\"p\">,</span>\n      <span class=\"nt\">\"main\"</span><span class=\"p\">:</span> <span class=\"s2\">\"Clear\"</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n  <span class=\"p\">],</span>\n  <span class=\"nt\">\"wind\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"deg\"</span><span class=\"p\">:</span> <span class=\"mi\">360</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"speed\"</span><span class=\"p\">:</span> <span class=\"mf\">5.82</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</pre><p>In the <code>render()</code> method in <code>DisplayWeather</code>, we used:</p><pre><span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">temp</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">main</span>\n<span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">description</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">weather</span><span class=\"p\">[</span><span class=\"mi\">0</span><span class=\"p\">]</span>\n</pre>\n<div class=\"action\">\n<p></p>\n\n<p>Find <code>main.temp</code> in the JSON snippet above</p>\n</div><p>This gives us 54.36 which is the temperature in F.</p><div class=\"action\">\n<p></p>\n\n<p>Next find <code>weather[0].description</code> in the JSON snippet above.</p>\n</div><p>Weather is an array which is why we need to get the first element with <code>[0]</code>.</p><p>Great work on <strong>using Props and State to configure and manage components in this chapter!</strong></p>"},{"id":"T0E6OlNlY3Rpb24tNzkzMw==","title":"Product So Far","htmlContent":"<p>Save and reload the app, you should now be getting the temperature of where you're at with a short description of the weather.</p><p><strong>Congrats on building your first native react app!</strong></p><div class=\"action\">\n<p></p>\n\n<p>As you go through FEW 2.4, reflect back to this tutorial and check that the material you're learning is builds upon what you learned here.</p>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkzNA==","title":"Feedback and Review - 2 minutes","htmlContent":"<p><strong>We promise this won't take longer than 2 minutes!</strong></p><p>Please take a moment to rate your understanding of learning outcomes from this tutorial, and how we can improve it via our <a href=\"https://forms.gle/A6DWJCR3mymeCLHx8\" target=\"_blank\">tutorial feedback form</a></p><p>This allows us to get feedback on how well the students are grasping the learning outcomes, and tells us where we can improve the tutorial experience.</p>"},{"id":"T0E6OlNlY3Rpb24tNzkzNQ==","title":"Stretch Challenges","htmlContent":"<div class=\"challenge\">\n<p></p>\n\n<p>Display some more of the weather info in the DisplayWeather component. Try these:</p>\n\n<ul>\n<li>humidity</li>\n<li>pressure</li>\n<li>name</li>\n</ul>\n\n<p>To do this you will need to get the value by navigating the Weather JSON. Then you'll need to add a  <code>&lt;text&gt;</code> component to display the value.</p>\n\n<p>Last you'll want to style the new elements. Add a new property to the <code>styles</code> object for the element that will use the style. Think of this like a class name you might assign to an HTML element.</p>\n\n<p>Next, assign an object with style properties under this property. Here are some properties you can use:</p>\n\n<ul>\n<li><code>fontSize</code></li>\n<li><code>fontWeight</code></li>\n<li><code>color</code></li>\n</ul>\n\n<p>Assign these properties values that work with React Native. React Native does not use the full selection of CSS values and generally doesn't use units.</p>\n\n<p>For example <code>fontSize</code> can be set to <code>24</code> and that's the equivalent of <code>font-size: 24px</code> in CSS terms.</p>\n\n<p>Some properties take keyword values these are always a string and React Native usually implements a subset of values supported by CSS. For example <code>fontWeight: 'bold'</code> is the same as <code>font-weight: bold</code> in CSS.</p>\n\n<p>Check the style properties by looking at the component reference. This will list all of the CSS properties supported by that component. Here is a link to the <a href=\"https://facebook.github.io/react-native/docs/text\" target=\"_blank\">Text Component</a>.</p>\n</div>"}]},"next":null,"previous":null}]}},"page":{"id":"T0E6OlBhZ2UtMTcxNA==","title":"Props and Weather Data","slug":"props-and-weather-data","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tNzkyOQ==","title":"Props and Weather Data","htmlContent":"<ol>\n<li><del>Build out the components of this app</del></li>\n<li><del>Implement the lifecycle methods for the Components</del></li>\n<li>\n<strong>Implement props and load in weather data</strong>\n\n<ol>\n<li><strong>Pass and use props to send information amongst components</strong></li>\n<li><strong>Load the weather data into the components</strong></li>\n</ol>\n</li>\n</ol><p>Before our app will actually display the weather data, we need to pass the weather data from App to DisplayWeather. Components all have a special property named <strong>props</strong> that are used for passing information from a parent component to a child component.</p>"},{"id":"T0E6OlNlY3Rpb24tNzkzMA==","title":"Passing Props","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Use props to pass the weather data from App to DisplayWeather in <code>App.js</code>:</p>\n<pre><span class=\"nx\">render</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n  <span class=\"k\">return</span> <span class=\"p\">(</span>\n    <span class=\"o\">&lt;</span><span class=\"nx\">View</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">container</span><span class=\"p\">}</span><span class=\"o\">&gt;</span>\n<strong>      <span class=\"o\">&lt;</span><span class=\"nx\">DisplayWeather</span> <span class=\"nx\">data</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"k\">this</span><span class=\"p\">.</span><span class=\"nx\">state</span><span class=\"p\">.</span><span class=\"nx\">weather</span><span class=\"p\">}</span> <span class=\"o\">/&gt;</span>\n</strong>\n    <span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n  <span class=\"p\">);</span>\n<span class=\"p\">}</span></pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkzMQ==","title":"Using Props","htmlContent":"<p>Props are used to passed data from a parent to a child component. Children get values from <strong>keys</strong> on the props object.</p><p>We want the <code>DisplayWeather</code> component to display a message when the weather data is loading. It also needs to display an error message if there was a problem, and otherwise display the weather data.</p><p>In the App component you set your data on the <strong>data prop</strong>. In <code>DisplayWeather</code> you get this as <code>props.data</code>, which we'll use to help us check the above conditions.</p><div class=\"action\">\n<p></p>\n\n<p>Add these two if statements above <code>return</code> in <code>/Components/DisplayWeather.js</code>:</p>\n<pre><span class=\"kr\">const</span> <span class=\"nx\">DisplayWeather</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">)</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n  <span class=\"c1\">// No data yet, so it must still be loading</span>\n  <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span> <span class=\"o\">===</span> <span class=\"kc\">null</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"k\">return</span> <span class=\"o\">&lt;</span><span class=\"nx\">Text</span><span class=\"o\">&gt;</span><span class=\"nx\">Loading</span><span class=\"p\">...</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n  <span class=\"p\">}</span>\n\n  <span class=\"c1\">// Cod is where codes go, so if an error occurred, the value would not be 200 (could be 400, 404, etc.)</span>\n  <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">cod</span> <span class=\"o\">!==</span> <span class=\"mi\">200</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"k\">return</span> <span class=\"o\">&lt;</span><span class=\"nx\">Text</span><span class=\"o\">&gt;</span><span class=\"nx\">An</span> <span class=\"nb\">Error</span> <span class=\"nx\">has</span> <span class=\"nx\">occurred</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n  <span class=\"p\">}</span>\n\n  <span class=\"c1\">// If no error and not loading, load/display weather data, grabbing the appropriate data from props</span>\n  <span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">temp</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">main</span>\n  <span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">description</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">weather</span><span class=\"p\">[</span><span class=\"mi\">0</span><span class=\"p\">]</span>\n\n  <span class=\"k\">return</span> <span class=\"p\">(</span>\n    <span class=\"o\">&lt;</span><span class=\"nx\">View</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">container</span><span class=\"p\">}</span><span class=\"o\">&gt;</span>\n      <span class=\"o\">&lt;</span><span class=\"nx\">Text</span> <span class=\"nx\">style</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"nx\">styles</span><span class=\"p\">.</span><span class=\"nx\">temp</span><span class=\"p\">}</span><span class=\"o\">&gt;</span><span class=\"p\">{</span><span class=\"nx\">temp</span><span class=\"p\">}</span><span class=\"err\">&#730;</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n      <span class=\"o\">&lt;</span><span class=\"nx\">Text</span><span class=\"o\">&gt;</span><span class=\"p\">{</span><span class=\"nx\">description</span><span class=\"p\">}</span><span class=\"o\">&lt;</span><span class=\"err\">/Text&gt;</span>\n    <span class=\"o\">&lt;</span><span class=\"err\">/View&gt;</span>\n  <span class=\"p\">)</span>\n<span class=\"p\">}</span>\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkzMg==","title":"Looking at the OpenWeatherMap Data","htmlContent":"<p>The weather data from OpenWeatherMap is a JSON object. It has a structure. To get information like the temperature and description you'll need to navigate the structure:</p><pre><span class=\"err\">Object</span> <span class=\"p\">{</span>\n  <span class=\"nt\">\"base\"</span><span class=\"p\">:</span> <span class=\"s2\">\"stations\"</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"clouds\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"all\"</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"cod\"</span><span class=\"p\">:</span> <span class=\"mi\">200</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"coord\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"lat\"</span><span class=\"p\">:</span> <span class=\"mf\">37.75</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"lon\"</span><span class=\"p\">:</span> <span class=\"mf\">-122.5</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"dt\"</span><span class=\"p\">:</span> <span class=\"mi\">1552710644</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"id\"</span><span class=\"p\">:</span> <span class=\"mi\">5391997</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"main\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"humidity\"</span><span class=\"p\">:</span> <span class=\"mi\">50</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"pressure\"</span><span class=\"p\">:</span> <span class=\"mi\">1021</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"temp\"</span><span class=\"p\">:</span> <span class=\"mf\">54.36</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"temp_max\"</span><span class=\"p\">:</span> <span class=\"mi\">59</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"temp_min\"</span><span class=\"p\">:</span> <span class=\"mi\">50</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"name\"</span><span class=\"p\">:</span> <span class=\"s2\">\"San Francisco County\"</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"sys\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"country\"</span><span class=\"p\">:</span> <span class=\"s2\">\"US\"</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"id\"</span><span class=\"p\">:</span> <span class=\"mi\">4322</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"message\"</span><span class=\"p\">:</span> <span class=\"mf\">0.0097</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"sunrise\"</span><span class=\"p\">:</span> <span class=\"mi\">1552745967</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"sunset\"</span><span class=\"p\">:</span> <span class=\"mi\">1552789093</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"type\"</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n  <span class=\"nt\">\"visibility\"</span><span class=\"p\">:</span> <span class=\"mi\">16093</span><span class=\"p\">,</span>\n  <span class=\"nt\">\"weather\"</span><span class=\"p\">:</span> <span class=\"err\">Array</span> <span class=\"p\">[</span>\n    <span class=\"err\">Object</span> <span class=\"p\">{</span>\n      <span class=\"nt\">\"description\"</span><span class=\"p\">:</span> <span class=\"s2\">\"clear sky\"</span><span class=\"p\">,</span>\n      <span class=\"nt\">\"icon\"</span><span class=\"p\">:</span> <span class=\"s2\">\"01n\"</span><span class=\"p\">,</span>\n      <span class=\"nt\">\"id\"</span><span class=\"p\">:</span> <span class=\"mi\">800</span><span class=\"p\">,</span>\n      <span class=\"nt\">\"main\"</span><span class=\"p\">:</span> <span class=\"s2\">\"Clear\"</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n  <span class=\"p\">],</span>\n  <span class=\"nt\">\"wind\"</span><span class=\"p\">:</span> <span class=\"err\">Object</span> <span class=\"p\">{</span>\n    <span class=\"nt\">\"deg\"</span><span class=\"p\">:</span> <span class=\"mi\">360</span><span class=\"p\">,</span>\n    <span class=\"nt\">\"speed\"</span><span class=\"p\">:</span> <span class=\"mf\">5.82</span><span class=\"p\">,</span>\n  <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</pre><p>In the <code>render()</code> method in <code>DisplayWeather</code>, we used:</p><pre><span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">temp</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">main</span>\n<span class=\"kr\">const</span> <span class=\"p\">{</span> <span class=\"nx\">description</span> <span class=\"p\">}</span> <span class=\"o\">=</span> <span class=\"nx\">props</span><span class=\"p\">.</span><span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">weather</span><span class=\"p\">[</span><span class=\"mi\">0</span><span class=\"p\">]</span>\n</pre>\n<div class=\"action\">\n<p></p>\n\n<p>Find <code>main.temp</code> in the JSON snippet above</p>\n</div><p>This gives us 54.36 which is the temperature in F.</p><div class=\"action\">\n<p></p>\n\n<p>Next find <code>weather[0].description</code> in the JSON snippet above.</p>\n</div><p>Weather is an array which is why we need to get the first element with <code>[0]</code>.</p><p>Great work on <strong>using Props and State to configure and manage components in this chapter!</strong></p>"},{"id":"T0E6OlNlY3Rpb24tNzkzMw==","title":"Product So Far","htmlContent":"<p>Save and reload the app, you should now be getting the temperature of where you're at with a short description of the weather.</p><p><strong>Congrats on building your first native react app!</strong></p><div class=\"action\">\n<p></p>\n\n<p>As you go through FEW 2.4, reflect back to this tutorial and check that the material you're learning is builds upon what you learned here.</p>\n</div>"},{"id":"T0E6OlNlY3Rpb24tNzkzNA==","title":"Feedback and Review - 2 minutes","htmlContent":"<p><strong>We promise this won't take longer than 2 minutes!</strong></p><p>Please take a moment to rate your understanding of learning outcomes from this tutorial, and how we can improve it via our <a href=\"https://forms.gle/A6DWJCR3mymeCLHx8\" target=\"_blank\">tutorial feedback form</a></p><p>This allows us to get feedback on how well the students are grasping the learning outcomes, and tells us where we can improve the tutorial experience.</p>"},{"id":"T0E6OlNlY3Rpb24tNzkzNQ==","title":"Stretch Challenges","htmlContent":"<div class=\"challenge\">\n<p></p>\n\n<p>Display some more of the weather info in the DisplayWeather component. Try these:</p>\n\n<ul>\n<li>humidity</li>\n<li>pressure</li>\n<li>name</li>\n</ul>\n\n<p>To do this you will need to get the value by navigating the Weather JSON. Then you'll need to add a  <code>&lt;text&gt;</code> component to display the value.</p>\n\n<p>Last you'll want to style the new elements. Add a new property to the <code>styles</code> object for the element that will use the style. Think of this like a class name you might assign to an HTML element.</p>\n\n<p>Next, assign an object with style properties under this property. Here are some properties you can use:</p>\n\n<ul>\n<li><code>fontSize</code></li>\n<li><code>fontWeight</code></li>\n<li><code>color</code></li>\n</ul>\n\n<p>Assign these properties values that work with React Native. React Native does not use the full selection of CSS values and generally doesn't use units.</p>\n\n<p>For example <code>fontSize</code> can be set to <code>24</code> and that's the equivalent of <code>font-size: 24px</code> in CSS terms.</p>\n\n<p>Some properties take keyword values these are always a string and React Native usually implements a subset of values supported by CSS. For example <code>fontWeight: 'bold'</code> is the same as <code>font-weight: bold</code> in CSS.</p>\n\n<p>Check the style properties by looking at the component reference. This will list all of the CSS properties supported by that component. Here is a link to the <a href=\"https://facebook.github.io/react-native/docs/text\" target=\"_blank\">Text Component</a>.</p>\n</div>"}]},"next":null,"previous":null}}},"staticQueryHashes":[]}