Podcast
Questions and Answers
What keyword is used to load values from other JavaScript files?
What keyword is used to load values from other JavaScript files?
- `let`
- `import` (correct)
- `const`
- `var`
Which keyword is used to create a variable whose value cannot be reassigned after its initial assignment?
Which keyword is used to create a variable whose value cannot be reassigned after its initial assignment?
- `var`
- `const` (correct)
- `let`
- `import`
In React Native, what are the properties passed to a component's constructor called?
In React Native, what are the properties passed to a component's constructor called?
- Props (correct)
- State
- Functions
- Elements
Which of the following is a description of 'state' in React Native?
Which of the following is a description of 'state' in React Native?
What is the purpose of the export
keyword in JavaScript?
What is the purpose of the export
keyword in JavaScript?
Which term describes the attributes of a React Native element?
Which term describes the attributes of a React Native element?
Which variable declaration should be avoided unless maintaining legacy code?
Which variable declaration should be avoided unless maintaining legacy code?
What does the fetch()
method primarily return?
What does the fetch()
method primarily return?
What is the purpose of the json()
method when used with a Response object from the Fetch API?
What is the purpose of the json()
method when used with a Response object from the Fetch API?
If you want to customize an HTTP request using fetch()
, what is the purpose of the second argument?
If you want to customize an HTTP request using fetch()
, what is the purpose of the second argument?
What is a key advantage of the Fetch API over XMLHttpRequest?
What is a key advantage of the Fetch API over XMLHttpRequest?
What does the Fetch API provide for JavaScript?
What does the Fetch API provide for JavaScript?
Which HTTP concept does Fetch API integrate?
Which HTTP concept does Fetch API integrate?
In a fetch
request, to send data in the body, which method should be specified?
In a fetch
request, to send data in the body, which method should be specified?
What method is used to convert a JavaScript object into a JSON string for sending in a fetch
request body?
What method is used to convert a JavaScript object into a JSON string for sending in a fetch
request body?
What is the simplest usage of the fetch()
method?
What is the simplest usage of the fetch()
method?
In React Navigation, how do you specify options that apply to all screens within a Stack Navigator?
In React Navigation, how do you specify options that apply to all screens within a Stack Navigator?
What does a JavaScript implementation in React Navigation allow?
What does a JavaScript implementation in React Navigation allow?
What does navigation.navigate('RouteName')
do in React Navigation?
What does navigation.navigate('RouteName')
do in React Navigation?
How can you programmatically navigate back to the first screen in a stack using React Navigation?
How can you programmatically navigate back to the first screen in a stack using React Navigation?
Which of the following is a navigator type in React Navigation?
Which of the following is a navigator type in React Navigation?
Which method is used to save data in AsyncStorage?
Which method is used to save data in AsyncStorage?
What preprocessing tool does vanilla React Native use?
What preprocessing tool does vanilla React Native use?
What function retrieves data from AsyncStorage?
What function retrieves data from AsyncStorage?
What does ES6 stand for?
What does ES6 stand for?
Which AsyncStorage method removes a specific item?
Which AsyncStorage method removes a specific item?
What does AsyncStorage.clear()
do?
What does AsyncStorage.clear()
do?
Which method retrieves all keys in AsyncStorage?
Which method retrieves all keys in AsyncStorage?
Which function allows you to save multiple key-value pairs in AsyncStorage?
Which function allows you to save multiple key-value pairs in AsyncStorage?
Which method is used to fetch multiple values from AsyncStorage?
Which method is used to fetch multiple values from AsyncStorage?
Where should the NavigationContainer typically be placed in a React Native application?
Where should the NavigationContainer typically be placed in a React Native application?
Which method selectively updates properties instead of replacing all child properties?
Which method selectively updates properties instead of replacing all child properties?
What triggers the callback function in onValue()
?
What triggers the callback function in onValue()
?
What does onValue
return?
What does onValue
return?
What will val()
return if a location in the database has no data?
What will val()
return if a location in the database has no data?
What type of argument does the onValue
method take?
What type of argument does the onValue
method take?
What is the data passed to the callback function in onValue()
?
What is the data passed to the callback function in onValue()
?
What is the primary use of the onValue
function?
What is the primary use of the onValue
function?
What is the effect of calling update()
?
What is the effect of calling update()
?
When does the onValue
event trigger with the initial data?
When does the onValue
event trigger with the initial data?
What kind of child property is 'name/first'?
What kind of child property is 'name/first'?
Flashcards
Component
Component
A modular, reusable building block of a user interface in React Native.
Import
Import
Used to load values from other JavaScript files; uses relative paths.
Export
Export
Used to make values available for importing by other JavaScript files.
Let and Const
Let and Const
Signup and view all the flashcards
Props
Props
Signup and view all the flashcards
State
State
Signup and view all the flashcards
JSX Attributes as Props
JSX Attributes as Props
Signup and view all the flashcards
navigation.navigate('RouteName')
navigation.navigate('RouteName')
Signup and view all the flashcards
navigation.push('RouteName')
navigation.push('RouteName')
Signup and view all the flashcards
navigation.goBack()
navigation.goBack()
Signup and view all the flashcards
navigation.popToTop()
navigation.popToTop()
Signup and view all the flashcards
Fat Arrow Functions
Fat Arrow Functions
Signup and view all the flashcards
Fetch API
Fetch API
Signup and view all the flashcards
fetch() Method
fetch() Method
Signup and view all the flashcards
Basic Fetch Usage
Basic Fetch Usage
Signup and view all the flashcards
Response Object
Response Object
Signup and view all the flashcards
json() Method (Response)
json() Method (Response)
Signup and view all the flashcards
Customizing Fetch Requests
Customizing Fetch Requests
Signup and view all the flashcards
Method (Fetch Options)
Method (Fetch Options)
Signup and view all the flashcards
Headers (Fetch Options)
Headers (Fetch Options)
Signup and view all the flashcards
Body (Fetch Options)
Body (Fetch Options)
Signup and view all the flashcards
update() method
update() method
Signup and view all the flashcards
onValue function
onValue function
Signup and view all the flashcards
Unsubscribe function
Unsubscribe function
Signup and view all the flashcards
Single Screen App
Single Screen App
Signup and view all the flashcards
Native Navigation (React Native)
Native Navigation (React Native)
Signup and view all the flashcards
React Native Navigation
React Native Navigation
Signup and view all the flashcards
DataSnapshot
DataSnapshot
Signup and view all the flashcards
unsubscribe()
unsubscribe()
Signup and view all the flashcards
Database Reference (ref)
Database Reference (ref)
Signup and view all the flashcards
onValue event
onValue event
Signup and view all the flashcards
React Navigation
React Navigation
Signup and view all the flashcards
JavaScript Implementation (Benefits)
JavaScript Implementation (Benefits)
Signup and view all the flashcards
Stack, Tab, and Drawer Navigators
Stack, Tab, and Drawer Navigators
Signup and view all the flashcards
AsyncStorage Functions
AsyncStorage Functions
Signup and view all the flashcards
AsyncStorage.setItem(key, val)
AsyncStorage.setItem(key, val)
Signup and view all the flashcards
AsyncStorage.getItem(key)
AsyncStorage.getItem(key)
Signup and view all the flashcards
AsyncStorage.removeItem(key)
AsyncStorage.removeItem(key)
Signup and view all the flashcards
AsyncStorage.clear()
AsyncStorage.clear()
Signup and view all the flashcards
NavigationContainer
NavigationContainer
Signup and view all the flashcards
NavigationContainer Usage
NavigationContainer Usage
Signup and view all the flashcards
Study Notes
Lecture 2: Introduction to Components and JavaScript
- Lecture introduces components and Javascript and provides a link for further reading.
- Link provided: https://www.reactnative.express/
Overview for today
- The lecture covers components, let and cosntant, state and props, creating a component and events
Imports and Exports
import
keyword loads values from other Javascript files via relative pathexport
keyword exposes values for importing
let and const
- Use
let
andconst
to declare variables and constants. - Avoid variable declarations with
var
unless maintaining legacy code. - Example:
let myVariable = 42
,const myConstant = 42
Component API: Handling App Changes and Defining Props and State
- Key question addressed: how to make an app respond to changes like button clicks or network requests
Component API: Props
- Properties passed to the constructor of a component are called
props
. - Parents can pass props down to children, but not the other way.
- JSX
attributes
become parameters calledprops
of the React element. - Value of an attribute can be any JavaScript expression when wrapped in curly braces.
- Example: bar={baz} which would set the value of bar prop to baz.
Component API: State
State
: An object with details about how a Component should render.- Name of the object is literally
state
Component API: Children
- Any children element should go between the opening
View
tag, e.g<View>
and closingView
tag, e.g</View>
.
Components
- React components are reusable building blocks to create the user interface.
- Components are the type of the React element.
- Build-in components are
View
andText
. - Custom Component can also be defined
Defining Components
- Two ways to define a React component: Function components and Class components.
- Function components take parameters (called props) as input, and return a React element e.g.
function MyComponent({ title }) {
return (
<View>
<Button title={title} color="#1ACDA5" />
</View>
);
}
- Class components are a class that extends
React.Component
and implements a render method
class Mycomponent extends React.Component{
render(){
return (<View/>)
}
}
Defining Function Components
- Function component is a function that returns a React element.
import React from 'react'
import { Button, View } from 'react-native'
export default function MyComponent() {
return (
<View>
<Button title="Press me!" color="#1ACDA5" />
</View>
)
}
Defining Class Components
- Can create components by subclassing
React.Component
and overriding the render() method - Props are accessible as
this.props
Composing Components
- Custom Components like
MyComponent
can be used as built-in ones likeView.
- Use props to communicate between components.
Events
- Some components trigger events/callbacks in response to user input.
- To add an event handler, pass a function as a prop to a React element.
Networking
- Many mobile apps need to load resources from a remote URL.
- Make a POST request to a REST API or fetch static content from another server
Using Fetch
- React Native provides Fetch API for any networking needs.
- Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before.
Making Requests
- To fetch content from an arbitrary URL, pass the URL
- Example:
fetch('https://mywebsite.com/mydata.json');
Using the Fetch API
- Fetch API provides a JavaScript interface for accessing and manipulating parts such as requests and responses.
- Fetch API provides a global
fetch()
method for fetching resources asynchronously across networks, and it provides an easy, logical way of doing so. - Fetch is promise-based alternative whereas
XMLHttpRequest
is callback based. - Fetch integrates advanced HTTP concepts like CORS and other extensions to HTTP are integrated.
Basic Fetch Request
- The simplest use of
fetch()
takes one argument path to the resource you want to fetch. fetch()
does not directly return the JSON response body but instead returns a promise that resolves with a Response object.
async function logMovies() {
const response = await fetch("http://example.com/movies.json");
const movies = await response.json();
console.log(movies);
}
The Response Object
Response
object does not directly contain the actual JSON response body and instead is a representation of the entire HTTP responsejson()
method is used to extract the JSON body content from the Response object; it returns a second promise that resolves with the result of parsing the response body text as JSON.
Making an HTTP Request
- Fetch takes an optional second argument to customize the HTTP request.
- It may specify additional headers or make a
POST
request.
- It may specify additional headers or make a
fetch('https://mywebsite.com/endpoint/', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstParam: 'yourValue',
secondParam: 'yourOtherValue',
});
});
Handling the Response
- Networking is asynchronous operation so Fetch method will return a Promise to make straightforward to work with.
const getMoviesFromApi = () => {
return fetch('https://reactnative.dev/movies.json')
.then(response => response.json())
.then(json => {
return json.movies;
})
.catch(error => {
console.error(error);
});
};
- Also use the async / await syntax in a React Native app
- Remember to catch any errors that may be thrown by fetch
Basic Fetch Request
- Example of using Fetch for web requests
import React, {useEffect, useState} from 'react'; // for managing state
import {ActivityIndicator, FlatList, Text, View} from 'react-native'; // to display our objects for our data
const App = () => {
const [isLoading, setLoading] = useState(true); // initially set to true
const [data, setData] = useState([]); // in this way is gonna be an empty array
const getMovies = async () => {
try {
const response = await fetch('https://reactnative.dev/movies.json');
const json = await response.json(); //put the response in Jason format
setData(json.movies); // we gonna set our data with json.moviw(movie inside Jason file in the website)
} catch (error) { // catch the error
console.error(error);
} finally {
setLoading(false); // if the loading is false we can display our flat list
}
};
useEffect(() => { // to use use effect that hook that we import
getMovies();
}, []);
Security
Topics for storing sensitive information, authentication, network security, and tools the you secure your app
Storing Sensitive Info
- Never store sensitive API keys in your app code
- Tools to use in place:
react-native-dotenv
andreact-native-config
- Tools to use in place:
- If there needs to be an API build an orchestration layer using: AWS Lambda or Google Cloud Functions
Storing Sensitive Info (Best Practices)
- Choose the right type of stoage based on sensitively
- Persistent vs Unpersisted
Async Storage
- Community maintained module for React Native asynchronous, uencrypted, key value store
- Not dshared between apps = sandbox environment
- DO use: for persisting non-sensitive data
Secure Storage
- There are pre-existing solutions for Android and iOS platforms because React Native doesn't come bundled with any way of storing sensitive data
- Keychain Services
- Secure Shared Preferences
Lecture3A(Lists and TextInputs)
- This lecture will introduce text inputs, as well as covering HOOKS,
Scrollview
,Flatlists
andsectionlist
useState
useState
is the first hook learnt- It can be used to intialize the state at the tope of your function component
- Example*:
import { useState } from "react";
function FavoriteColor() {
const [color, setColor] = useState("");
- We destructute the returned values from
useState()
- The first value is used for current states
- The second value is used for updating the state
useEffect
useEffect
is the second hook and lets you synchronizeuseEffect
react hook lets your synchronize component from external states- Syntax :
useEffect(setup,dependencies?)
- Call
useEffect
at the top level of your component to delcare an effect -setup: The function wit your Effect's logic -optional dependencies: The list of all reactive values referenced inside of the setUp cord - There are a variety of
useEffect
examples such as; no dependency passed, an empty array, or props or state values
ScrollView
- Native React Component Library
- Has multi-child options
- Can scroll vertically or horizintally
- It scrolls vetically, and to mention horizontal scroll we state
horizontal: true
ScrollView Attributes
showsHorizontalScrollIndicator
: Show an indicator for horizontal scrollingScrollEnabled
: If we don't want to scroll our content, to define it falsehorizontal
: In case if we want to have horizontal scrolling, set the attribulte as true,horizontal = true
Flatlist
- Like a
listview
, is used to hold items in a list -Provides important features like scolling horinzontally and verically -Designed to handle large datasets that might not fit on the device screen- Renders only current displaying items on a screen
Syntax for basic Flatlist
import {Flatlist } from 'react-native';
<FlatList
data={
// data to be rendered in flatlist
}
Separator Component={
// A separator to separate data items
}
renderData= {({ singledata})
// Single data view
}
/>
-Can rendered using 2 props. The flatlist
- Other optional ones include
Separator,Header
,
RefeshControl
- Provides and indivdual
refeshControl
- Implment pull-to-refresh to add the functions use
RefreshingControl
-when you initiate a pull to refresh gesturerefershControl
triggers- executes new data from the sever to add to on screen
TextInput
- Fundatmental component for inputted text
- Provides conficguaribility for functions; autocorrection,capitalation.
Lecture - Firebase Database
- This lecture will cover local data / over network data + the set up for firebase
- Local vs Over Network Data Table
Local Data | Over network data |
---|---|
Performance and size are usually not an issue | Fetches have to be tailored to what is needed, since it is fetched over the internet |
Delivery is guaranteed | Delivery depends on the user's network |
Typically accessed by 1 session of the app at a time | Accessed by an unknown number of sessions of the app at a time |
Doesn't worry about concurrency | Concurrency is at the heart of it |
Is Firebase?
- Firebase is a backend-as-a-service
Firebase Realtime Database
-Syncing with real time for JSON data, a could hosted, NoSQL
database
- Stores , syncs with and cloud database that remians
-The SDK's share one Realtime Database interace with the newest data on the JSON's every connected client
-Follow set up instructions at
https://console.firebase.google.com/u/0/
Initialize SDK Into Project
import { initializeApp } from 'firebase/app';
// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {
apiKey: 'api-key',
authDomain: 'project-id.firebaseapp.com',
databaseURL: 'https://project-id.firebaseio.com',
projectId: 'project-id',
storageBucket: 'project-id.appspot.com',
messagingSenderId: 'sender-id',
appId: 'app-id'
};
const app = initializeApp(firebaseConfig);
- Follow set up instructions at
https://console.firebase.google.com/u/0/
Realtime Database Refernces
- Reference your JSON data like this
users /users: phone-number
API
Ref
imports ref to correspond return database, it contains root of databaseset
Writes data to location and overwrites it- Ex:
set(ref(Db, id)
- Ex:
remove
Imports the process of removing from the database Ex:remove(Ref)
onValue
- Primary way for reading database. Callback will trigger from initial changes.
- Invoke the returned callback to stop receiving updates
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge of JavaScript fundamentals including variable declarations, React Native, and the Fetch API. Explore concepts like state in React Native, exporting modules, element attributes, and customizing HTTP requests. Understand the advantages of Fetch API and its integration with HTTP.