React Native Tutorial #12 - Alerts
Key Takeaways
Demonstrates how to use Alert components in React Native
Full Transcript
alright than my friends so we've created this 2 News app now but what I'd like to do is just add a couple more features to make this app Sparkle if you will so the first thing I'm gonna do is a tiny little bit of validation in here to make sure I use actually type something instead of just clicking add to do because that makes no sense right there and then secondly I also want to show you how to do alerts so a little message that pops up so what we're gonna do is validate this field if say for example the word that a user types in here is less than three letters long or something like that then what we're gonna do is show an alert to say look you need to add something in that's a bit longer so that's what we're going to do the first thing we need to do is perform this check inside the submit handle of when a user clicks on this that is the point we want to check look whatever they've typed in here does that equal to at least three or four characters long so we need to do a little if check inside this submit handler to do just that so let's say if and then in here or say text which is the text we receive and that is the value inside the text input if that dot length is going to be over three so at least three characters long then we're going to update the state so let's grab all of this stuff set to dues cut it and paste it all right here so that's the case if this is at least three characters long so let me try this out first of all and wait for this to reload blah blah okay so if I just type in for example D hard to do it's not going to add it D D still doesn't add it D D D nope because it needs to be greater than three but the minute I add a fourth character it is gonna add that so that's fine but if it's say two characters and we're trying to add it then we don't really know why it's not adding this nothing's telling us we can't add something that's two letters long so that's the point we want to add an alert so if this fails right here this check instead of setting to do is what we're going to do is instead show and alert now to do that we need to import the alert components from react native that comes with it out of the box so in here now we can then say alert dots alert we call the alert method on the alert object and inside here what we need to do is pass through a few different arguments the first one is going to be the title of the alert and we'll just say oops so that's the title the second one is going to be some kind of message and I'm going to say - duze must be over three cars long so three characters long and I've done that all in capitals I really shouldn't do that so let's write this again - duze must be over three chars long and then the final parameter is going to be an array over here and inside that array is going to be some different objects and each object represents a little button that's going to be on the alert and when we click on that button I'll press that button it's going to close the alert now inside this object we can specify the text of that button which is going to be in this case understood we can also add an on press property and that could be just an anonymous function which is going to say console dot log and then alert closed okay because when we click on this button it is going to close the alert okay and that's all there is to it so let me save that now and see if this works so if we come over to the form in a second when it loads and try just adding one character out to do and we get this alert so there's the title the text and then the bottom when I click on this one just do it it closes it and if I take a look at the tools over here we can see it logged that to the console alert closed when we clicked on that if I do it for two characters it pops up again and we do it for three pops up again if I do it for four we don't get that any adds it to the list so there we go that's how we can use a little bit of validation and also show an alert
Original Description
Hey gang, in this React Native tutorial we'll take a look at alert boxes and how to use them in our app.
----------------------------------------
🐱💻 🐱💻 Course Links:
Course files - https://github.com/iamshaunjp/react-native-tutorial
🐱💻 🐱💻 Other Related Courses:
+ Complete React Tutorial - https://www.youtube.com/watch?v=OxIDLw0M-m0&list=PL4cUxeGkcC9ij8CfkAY2RAGb-tmkNwQHG
+ React Hooks & Context Tutorial - https://www.youtube.com/watch?v=6RhOzQciVwI&list=PL4cUxeGkcC9hNokByJilPg5g9m2APUePI
+ Modern JavaScript Tutorial - https://www.youtube.com/watch?v=iWOYAxlnaww&list=PL4cUxeGkcC9haFPT7J25Q9GRB_ZkFrQAc
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
Related AI Lessons
⚡
⚡
⚡
⚡
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
The US Frontend Engineer Market in 2026: A Data-Driven Reality Check (and the Bias That Stops Us Seeing It)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI