React Training
  • React JS Library
  • Roadmap
  • Training OutLine
  • React js basics
    • Understanding React JS
    • React JS a framework?
    • Setting Up React
    • Say Hello to React
    • Everything is a Component
    • Create-react-app
  • React Building Blocks
    • JSX and Babel
    • One Way Data Flow
    • Virtual DOM
    • V of MVC
    • React Terminology
    • React Tooling
  • Day 01
    • Day 01 OutLine
    • All About JSX
    • React Tools/ npm & webpack
    • Introduction of Webpack
    • Hello world using webpack
      • Webpack Setting up with React
    • NPM Scripts | Package JSON
      • Package.json file
    • React JS Principles
      • One Way Data Flow
      • V of MVC
      • Virtual DOM
    • Create React App - Part-1
    • Create React App - Part-2
  • Day 02
    • Quick Recap
      • Quiz
    • State & Props
      • State & Props in Depth
      • State Vs Props | Compare
    • React LifeCycle Methods
      • React LifeCycle Methods for V-0.16 x
    • Constructor | Lifecycle
    • Write Flicker App | First App
  • Day 03
    • Quick Recap
    • Life Cycle Flow
      • Birth and Mounting
      • Initlization and Construction
      • Pre Mounting
      • Render Method
      • componentDidMount
    • Type of React Components
      • Examples- Quick Compare
      • Class and Functional components
      • Functional Components
    • YouTube application
      • Component Design
    • All in One LifeCycle
  • Assignment
    • React App development
  • Day 04
    • Quick Recap on Lifecycle
    • Lifecycle deprecated/New Methods
      • New Lifecycle Methods
    • Lets Build App Netflix | Mock
  • Assignment
    • Github battle App | Assignment
  • Day 05
    • Quick Recap : Hooks
    • ES6 Features | Hands-on
      • ES6 Code Examples
    • Next Stop - React Router | SPA
      • Code examples | Router
      • React Router Building Blocks
      • Application using react-router-dom
  • Day 06
    • Router V4 | Quick Recap
    • ES2015 | 16 Quick Recap
    • LifeCycle Methods -Part-1
    • LifeCycle Methods -Part-2
  • Day 07
    • Quick Recap | New Lifecycle
    • Quick Recap | React Routing
    • Context API | React JS
      • component with context APIs
      • Context API | examples
    • App using Hooks/Context APIs
  • Assignment
    • Assignments
  • State Management Day-08
    • Quick Recap
    • Managing React State
      • What is Redux
      • Understanding Redux
      • Hello World "Redux"
  • React Redux Day - 09
    • Redux State Manager
    • Redux Redux Development
    • Simple Application | Redux
  • Redux Live Application Day -10
    • Redux with existing Application
      • Redux with React App
      • Lets Build More Apps
      • Should I use Redux from Dan
    • Quick Look at JS in React
    • Learn By Reading
  • miscellaneous Items - Day 11
    • Hooks useReducer
    • Hooks useContext
    • Hooks useRef
    • Hooks useEffect
    • Hooks useState
    • Lazy Loading and code splitting
    • Styling React Component
  • React Next Step - Day 12
    • Topics
    • Jest and Enjyme Testing
    • Examples: Testing
  • React Native
    • What is React Native
    • Setting up Environment
      • Linux Systems
    • React Native Hello World App
    • React Native Architecture
    • React Native Vs Native
    • Expo Cli or React Native CLI
  • React Native core Fundamental
    • React Native "Hello World"
    • Course OutLine
    • Getting started with Expo App
    • Layout with Flexbox
    • Working with Styles and Events
    • Manging Component State and Props
    • Build Simple Task List Application
  • What to Debug & How to Debug
    • Debug React Native Application
Powered by GitBook
On this page
  • How to Run on Actual Device
  • Hello world App

Was this helpful?

  1. React Native core Fundamental

Getting started with Expo App

PreviousCourse OutLineNextLayout with Flexbox

Last updated 4 years ago

Was this helpful?

Expo is a free and open source toolchain built around React Native to help you to build native iOS and Android projects using JavaScript and React.

Since you have already installed Node.js, use npm command to install Expo CLI

npm install -g expo-cli

Now you can use expo init to create new React Native Project

expo init helloWorld

Then you can choose a template

Image for post

If you want a project with screen navigation, chose tabs option. Since we are creating simple hello world app in this blog, I am going to use blank option.

To start the development server, move to a project folder and execute npm start.

cd helloWorld
npm start

Then the server starts and you can see QR code in both browser and terminal Expo dev tools running on a browser

How to Run on Actual Device

Next important thing is to make sure your mobile is connected to the same Network as your computer.

Hello world App

Now, Let’s look at the code.

You can see in the project, you have app.json file. You can find all the configurations related to app in there, such as app name, sdk version, icon etc..

And there is package.json file with list of dependencies for the app.

Then you have App.js. It is the starting point of your app. You can see render method there, it has View component which is used to wrap the Text component.

In the bottom of App.js file you can see styles object, which defines the styles for your UI components. In react native, moving styles from render method improve the code readability. You can define different styles to different UI components.

Let’s remove the existing code in App.js and write following code to change the Hello World! text to Hello John! on a button click.

Remember to import Button from ‘react-native’

export default class App extends React.Component {
   constructor(props){
     super(props);
     this.state = {
     name: 'World!',
     }
   }
   onClick = () => {
     this.setState({
     name: 'John!',
     })
   };
   render() {
   return (
     <View style={styles.container}>
       <Text>Hello {this.state.name}</Text>
       <Button 
            onPress={() => {this.onClick()}} 
            title='Click me'
            color='#4169E1'>
       </Button>
     </View>
   );
   }
}
const styles = StyleSheet.create({
   container: {
     flex: 1,
     backgroundColor: '#fff',
     alignItems: 'center',
     justifyContent: 'center',
   }, 
   nameText: {
     fontSize: 50,
     padding: 15,
   }
});

In the above code, Text component will display the name in state. Initial value of name in the state is World! and pressing Click me button will call onClick function which change the value of name to John!.

In this code I added style nameText to Text Component, which sets fontSize and add padding to the Text.

When it comes to Button, React Native provides very limited options for that component. Button component renders the native button on the platform. Because of this, it does not have style prop. It has its own set of props. So in order to change the button color I passed #4169E1 to color prop.

I think you got a basic idea about how to work with React Native. So, now you can try your first react native app.

Image for post
Image for post

To run this application on actual device, First you have to download the Expo app from Store or (depends on your device)

Then, open Expo app and scan QR code in your terminal or browser. Now, you can see your app running on the device.

Image for post

If you want more control on appearance, use instead of button.

Image for post
Google Play
App Store
TouchableOpacity
Image for post