Material UI Tutorial #12 - Layout Component
Skills:
HTML & CSS70%
Key Takeaways
Creates a layout component using Material UI to wrap page content
Full Transcript
all right then so now we have all of this content right here what i'd like to do is kind of step away from this a little bit and create a layout file that is going to surround this content and not just the content on this page but also the content on the create page now this layout component is going to consist of eventually a side draw with some links on to these different pages and also an app bar at the top with maybe a title or something like that so what i'd like to do in this video is just create a layout component for this layout file and then that layout component is going to wrap all of the content on both of the pages so then let's create that file first of all i'm going to do that inside the components folder so let's create a layout.js file and then i'll boilerplate this this is called layout and then inside let's just place some text for now layout now how do we get this to wrap all of our pages well all we need to do is come to the root components where we output these pages right here and it's going to surround this switch component now it needs to surround this one and not the router one because we are going to use the router inside the layout component so it has to go inside the router component so all i'll do is say layout right here i'm going to click on this to auto import it at the top and then i'm going to wrap it around the switch component so let me grab that and place it at the bottom over here so now if i save this what's going to happen well if we come over here and we're on the create page we just see this text right here layout and if we go to the home page we just see that text layout and that's not what's supposed to happen i want to still see the page content but i want to see this layout content wrapping around that page content so why is this not working well it's because we have this layout component right here so react looks into that layout component and it says well okay this is the content for that so i'm just going to display that and it discards all of the children all of these things inside the layout component now we don't want it to discard the children we want to output the children but we need to output them explicitly inside this layout components now we get access to the children on the props directly here so we can destructure that by saying children like so and this children property represents all of this content right here so all we need to do is output that somewhere inside this layout so i could now just say children like so and that's gonna output them so we can see all the content here and if we go to forward slash create we see all the content here so this is pretty much now like we had it before before we even started the layout component only now we can add in content above it or below it if we want a footer or a sidebar somewhere as well so it makes it a bit more flexible this approach all right then so what i'd like to do is first of all wrap this in some kind of div so let me do a div and open this up we'll place the children inside it now i also want to give a class to this div so we can style it a little bit and we're going to be using make styles to create this class in a second so i'll set this equal to classes dots and we'll call it page because all of the page content is essentially going to go here all right then so we need to use the make styles now to create these classes so let's do that i'm going to say const use styles is equal to make styles i'm going to click on this to auto import it at the top and inside here we pass a function so all i want to do is make one class which is the page class and that is going to have a background color so we'll say background and that's going to be a hash code so f 9 f9 f9 it's a really light gray after that i'm also going to say the width of this will be 100 all right then so if i save this now then it says right here classes is not defined that's because we've not used this u styles hook right here so let's do that i'll say const classes is equal to use styles like so okay so save that now and now we see it and you should just be able to make out that light gray background of the content and it should be the same for the home page if we go there yep we get a light grey background awesome so that's worked all right so eventually like i said we're also going to have an app bar inside here so let's do a little comment for that right here up bar at the top we're also going to have a side draw so a comment for that as well now we're not going to make those in this video but we are going to start on the side draw in the next tutorial but at least now we have our layout component ready to go
Original Description
🐱💻 🐱💻 Course Files:
+ https://github.com/iamshaunjp/material-ui-tut
🐱👤🐱👤 JOIN THE GANG -
https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg/join
🐱💻 🐱💻 My Udemy Courses:
+ Modern JavaScript - https://www.thenetninja.co.uk/udemy/modern-javascript
+ Vue JS 3 & Firebase - https://www.thenetninja.co.uk/udemy/vue-and-firebase
+ D3.js & Firebase - https://www.thenetninja.co.uk/udemy/d3-and-firebase
🐱💻 🐱💻 Useful playlists:
+ Full React tutorial - https://www.youtube.com/watch?v=j942wKiXFu8&list=PL4cUxeGkcC9gZD-Tvwfod2gaISzfRiP9d
+ JSON Server Tutorial - https://www.youtube.com/watch?v=mAqYJF-yxO8&list=PL4cUxeGkcC9i2v2ZqJgydXIcRq_ZizIdD
🐱💻 🐱💻 Other links:
+ Material UI docs - https://material-ui.com/getting-started/installation/
+ Get VS Code - https://code.visualstudio.com/
🐱💻 🐱💻 Social Links:
Facebook - https://www.facebook.com/thenetninjauk
Twitter - https://twitter.com/thenetninjauk
Instagram - https://www.instagram.com/thenetninja/
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: HTML & CSS
View skill →Related Reads
📰
📰
📰
📰
The Enter key that submits your form while a Japanese user is still typing
Dev.to · greymoth
The two-Reacts bug: when packages aren't singletons
Dev.to · r9v
🚀 Introducing Prism Guard — An Open Source Frontend Architecture Intelligence Platform
Dev.to · Ritumoni Sarma
The Death of the Heavy Hydration Layer
Dev.to · Amodit Jha
🎓
Tutor Explanation
DeepCamp AI