Material UI Tutorial #15 - More on makeStyles
Skills:
React90%
Key Takeaways
Explains the use of makeStyles hook in Material UI
Full Transcript
all right then gang so in this lesson i just want to take a quick step back to this make styles function right here and talk more about that so we already covered the basics of using this function to create css rules like this or classes and then we can access those in our component by invoking that hook right here now there's a couple of extra things i want to talk about that we can do with this function first of all what if i want to apply some padding for example to the page class well yeah i could just say the padding down here and hardcode a value like 20 but i might also want to use the spacing values as defined on the default theme object now you could find out those manually and add them in here or we could inject the theme object directly into this make styles object and access it that way now to do this all we have to do is turn this object parameter right here into a function which returns an object so right now this is going to do exactly the same thing if we return an object right here and pass in all of these properties like so so this is exactly the same now as before but instead of just passing in the object as a parameter we're now passing a function which returns the object the same kind of thing but doing it this way it means we can take in arguments here and an argument that we automatically get access to is the theme object so now we can use that theme object and all the different properties on it inside our classes so for instance i could say right here instead of hard coding the padding to be theme dot spacing to access the spacing values and this is a function and i want to pass in three so what that does is take the base spacing which is eight pixels i think for the theme and times is it by three so therefore we're going to get a padding of 24 pixels so if i save this we should see now a bit more padding around the page content awesome now i'm going to do the same thing for the title right here inside the draw so let me create a class for this i'm going to say title and then inside here i'm going to say padding and say theme dot spacing and then pass in two this time all right so we need to apply that class to the title which is right here so let's say class name is equal to classes dot title like so save it and preview and now this has a bit of padding awesome so the next thing i want to show you is how to pass optional arguments into make styles as well or into the different classes or properties that we generate with make styles so let me cross off the layout and instead come to the note card now the first thing i need to do is import it and use it so let me say const new styles is equal to make styles right here i'm going to enter onto that to import it and then we're not going to do a function to return an object here because we're not going to use the theme instead i'm just going to do an object and what i'm going to do is just make a test class and inside here i want a border property now the thing is i want this to be dynamic i want to do some kind of evaluation and if that evaluation is true i'll have a specific border if it's not true then i won't now i want that dynamic check to be based on the category of the note so we somehow need to pass in this note into make styles so we can use it so what i'm going to do is come down here and say const classes is equal to use styles just as we normally do but now i'm going to pass in as an argument this note so now inside different properties i could use a function which returns a property and inside this function i can take in the argument we're passing right here so i get access to the note now and i could evaluate it i could say if the note dot category is equal to work for example that's one of the categories in that case i want to apply a border so i'll return a value and it's going to be one pixel solid and red and now only if the category of the notes is equal to work will we have this border of one pixel solid and red on the test class if it's not work we won't so what i could do is try using this test class on the card so we'll apply the class name right here class name is equal to classes dot test so if we save this and preview now only this one has the red border and this is the one with the category of work so that's two things you can do with make styles first of all we could use a function to return an object and that function can take in the theme if we want to use theme values and also if we want to pass in extra arguments that we use in the different properties like this we can do and then the property can just be a function which takes in that argument so we can use it and also returns some kind of value
Original Description
In tis Material UI tutorial we'll talk more about the makeStyles hook . I'll hosw you how to access the theme object inside the hook, to use theme values & also show you how to pass arguments from your components into the makeStyles hook too.
🐱💻 🐱💻 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: React
View skill →Related Reads
📰
📰
📰
📰
I Spent Two Years Maintaining a React SPA. HTMX Rebuilt It in a Week
Medium · Programming
The 5 Levels of Front End Engineering (And Where Most Developers Get Stuck)
Medium · Programming
Browser-Based PDF Editing with Vue 3 and pdf-lib
Dev.to · sunshey
Say Goodbye To Electron?
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI