React Native Tutorial #21 - Navigating Around
Skills:
React90%
Key Takeaways
Builds a navigation system using React Native's Stack Navigator to navigate between screens
Full Transcript
our other gang so at the minute we've created this Homestuck navigator right here and registered these two different screens and then when we surround it with this create app container function it returns a component which we're rendering right here and this determines which screens currently show currently this one right here because it's at the top of this configuration but that's all its really doing at the minute we need a way now to navigate between these two different screens using this navigator so how exactly do we do that well first of all let's go to the home screen because that's the one that loads up automatically by default and what I'd like to do is place a button in this component and when we click on that button take us to the review details component over here so first things first let's import button up here and then let's create that button down here and it's self closing we need a title prop on this button which is going to say something like go to review debts okay so if I save this at the minute we should see that button over here but when we click it it's not really gonna do anything yet so if I click it nothing happens so we need an on press handle so what I'm going to do is add that right here on press and set that equal to some kind of function which I'm going to define up here so Const and we'll call this press Handler and set it equal to an arrow function now inside this arrow function what we want to do is then navigate to the review details screen now how exactly do we do that well when we configure our navigation step like this every screen that we configure automatically gets a navigation property on the props assigned to it so in here you know that we can take in props right well we get a property on the props called navigation so props navigation like that and we can use that then to navigate to different screens in the stack so I'm going to get rid of that because what I like to do instead taking the props directly is 2d structure what we need from the props and we're going to D structure navigation so now we have access to this navigation object right here and what we can do is say now navigation and we can use a method on that call navigate and in here we can pass a string and the string is going to be where we want to navigate to and it has to be one of these things the names of the different screens so either review details or home so not this name and not this name even though they're the same whatever you called it right here so we want to go to review details so let me copy that dude and paste it in here in a string that's where we want to navigate to so then react navigation is going to look at this and it's gonna find this property inside our screens object right here and it's gonna say okay well if you want to navigate there I'm gonna show this screen this component right here that we import it and it's gonna then take us to that and show it on the screen so let me save this now and see if this works I'm gonna whoops no it doesn't so this there's a problem with oh that's because we've not said right here what we wants happen on press so we want to run the press handle up function like so so let me save that now and hopefully how this will work okay so when we click on this now go to review details and we get that screen and take a look at this we have this arrow automatically in the header we did not have to do a thing to put that there react navigation and the stack navigates in particular automatically places that arrow there and it knows that we've come from another screen and if we press this it can take us back to that original screen so if we think back to our stack we had the home screen at the bottom then we clicked on the button and that added this screen to the stack on top now if we click on this arrow right here it's gonna pop this screen back off the stack and it's gonna show the home screen underneath so click on that and we can now see the home screen underneath awesome so that works now that's an easy way to navigate from one screen to another we can also use a diff method and that is the push method so let me say navigation dots push and then if we play seeing it review details this is going to do the same thing only this is a bit more explicit right so remember when we were talking about the stack to add something to the stack we push it on and to take it away we pop it off so this is a more explicit method right here but it's going to do exactly the same thing so let's save that and just test it out and again click on that button and it still works and if I click on the back button it still pops it off automatically now when we're using these two there's not really much difference in the two different methods and I'm going to stick with this one at the top navigate but when you're making more complex apps sometimes you need a little more granular control over the stack and how it works and then you can use this push method for that now just like we have a push method we have a pop method as well and remember that pops a screen off the stack and that's actually what's happening behind the scenes when we click on this arrow but we can manually do that as well so let me comment out this one and bring this one back first of all then I'm gonna go to the review details component over here and the same in this component I want to add a button now inside here that when we click it is going to pop that screen off the stack so it's going to do exactly the same thing as the arrow at the top but this is a more manual approach and sometimes you might want a button or a link or something that when a user presses on it takes you back so I'm going to show you how to do that so first things first let's import the button at the top and then down here will create that button and the title this time is going to be something like back to home screen so title is equal to back to home screen like so and then we also need an on press Handler so let's create a function up here to do that I'm going to say Const and then press handle again equal to a function and inside that function all we want to do is use navigation and remember we have to grab that the props so we destructor it navigation and again the reason we get access to this is because we've used this particular component in the stack navigator right so every component that we use in the stack navigator or automatically and gets this if we were to go to the about component we wouldn't get that because we've not configured that inside the stack navigator just the ones we've configured here and get access to it so we take that and we can use the go back method like so and that now pops a screen off the stack so now if I save this in fact let's not make the same mistake twice let's put press Handler in here then save it and see if this works so go to review details we can click on the back button that works let's do it again and this time click on this button and it does exactly the same thing it pops a screen off the stack and goes back to the home screen so now we know a little bit about how to navigate between screens let's add some data to the mix and see how it can pass data from one screen to another as well so basically we want a list of different reviews here eventually and when we click on a review we want to go to this screen and navigate here but we want to pass that particular review data into the component so we can render it so we'll see exactly how to do that in the next video
Original Description
Hey gang, in this React Native tutorial we'll see how we can use our stack navigator to navigate around our app from screen to screen.
----------------------------------------
🐱💻 🐱💻 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
More on: React
View skill →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