React Native for Beginners: Your Journey Starts With a ToDo List App

Harry Bloch
4 min readMay 24, 2023

--

Hello there, aspiring coders! Ready to dabble in some fun and productive app development? Perfect, because today, we're diving into the realm of React Native to create a super-useful and ultra-personalized ToDo List app. A personal assistant who lives in your pocket, always ready to remind you of the tasks at hand. How cool is that?

And the cherry on top? You'll be the one creating it!

Oh, and before we jump in, don’t forget to check out some of my awesome apps on the App Store! Shameless self-promotion, right? Let’s get started!

So, without further ado, let's delve into the wonderful world of React Native.

Step 1: Set Up Your Environment

Before we start throwing code around, we need to get our development environment ready. We'll need Node.js, a JavaScript runtime, installed on our machine. Just go to the Node.js website and download the latest LTS version.

We're also going to use Expo CLI, a tool that helps developers kick-start a new project without any hassle. Install it using npm (Node Package Manager, which comes bundled with Node.js) by running this in your terminal:

npm install -g expo-cli

Step 2: Create a New React Native Project

Now that the Expo CLI is up and running, let's create our project. Navigate to the folder where you want your project to live, and type this in your terminal:

expo init ToDoList

When prompted, select the blank template.

Step 3: Boot Up Your App!

Navigate into your new project folder with cd ToDoList, and start your app by typing expo start. This command launches a local server where your app will run. You'll see a QR code pop up in your terminal.

To preview the app on your phone, download the Expo app from your phone's app store, and scan the QR code using the Expo app. And voila! You can now see your app on your phone.

Step 4: Crafting the ToDo Screen

Alright! Now that we've set up our app, it's time to create a new screen for our ToDo List. Let's create a new file in your project directory named ToDoScreen.js and add some code to it:

import React from 'react';
import { Text, View } from 'react-native';

const ToDoScreen = () => {
return (
<View>
<Text>Welcome to the ToDo List!</Text>
</View>
);
}

export default ToDoScreen;

This little snippet will create a new screen with a simple welcome message.

Step 5: Let's Navigate with React Navigation

To navigate between different screens, we need to install a library called React Navigation. Run these commands in your terminal:

npm install @react-navigation/native
expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view
npm install @react-navigation/stack

Now that we have React Navigation installed, we can set up the navigation for our app.

Replace the existing content of App.js with the following:

import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import ToDoScreen from './ToDoScreen';

const Stack = createStackNavigator();

const App = () => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="ToDo">
<Stack.Screen name="ToDo" component={ToDoScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}

export default App;

Now, run your app with expo start, and you should see the "Welcome to the ToDo List!" message.

Step 6: The Actual ToDo List

We're going to have an array of tasks as our ToDo list. We'll display a TextInput and a Button for adding new tasks. Let's modify the ToDoScreen component:

import React, { useState } from 'react';
import { View, Text, FlatList, Button, TextInput } from 'react-native';

const ToDoScreen = () => {
const [tasks, setTasks] = useState([
{ id: '1', task: 'Buy Milk' },
{ id: '2', task: 'Walk the Dog' },
]);
const [input, setInput] = useState('');

const addTask = () => {
setTasks([...tasks, { id: Date.now().toString(), task: input }]);
setInput('');
};

return (
<View>
<TextInput
value={input}
onChangeText={setInput}
placeholder="Enter a task"
/>
<Button title="Add Task" onPress={addTask} />
<FlatList
data={tasks}
keyExtractor={(item) => item.id}
renderItem={({ item }) => <Text>{item.task}</Text>}
/>
</View>
);
}

export default ToDoScreen;

Congratulations! You've just created your first ToDo List app with React Native! How do you feel? Excited? Proud?

But remember, this is just the beginning of your app development journey. You can continue enhancing this app by adding features like marking tasks as completed, or setting deadlines for your tasks. The sky (and your imagination) is the limit!

If you enjoyed this process (I'm confident you did), do check out more superb apps right here or follow me on Twitter. They're just as engaging and even more handy.

Keep coding, keep exploring, and most importantly, keep having fun!

--

--