Complete React Tutorial (& Redux) #33 - Importing Images
Key Takeaways
Shows how to import and use images inside React components
Full Transcript
or rather than gang so I just want to give you a quick lesson now on how we can use images inside our components so to do this I'm going to use just an image of a pokeball to put a little background to each one of these different posts on the homepage so first of all you'll notice in my files over here I have a poke ball dot PNG file you can find this on my github repo I'm going to leave the exact link for that image down below in the description so just place that in your source folder directly in the source folder and we're going to use the inside this whole component so first of all to use an image inside a component what we have to do is import that image so at the top just say import and we'll call this pokeball from and then we need to jump out of the current directory and then grab the polka ball dot PNG file all right so that's what we're doing we're just importing this pokeball from this file now we can use this thing in the template down here so we want to output it for each individual post and I'd like to output that just above this div right here okay so the first div stays the same underneath that directly we're going to output this image so let's do an image tag first of all now the source of this image this is going to be this thing up here that we just imported and it's going to work out the source for us we don't have to do a path to the source we just have to output the name of the thing we imported in curly braces so poke ball and that's all there is to it let's give this a little alt description so a Pokeball like so save that and if you in the browser and we get this gigantic poke ball in each one of these things so that was very easy right all we had to do was import it and then use it as the source like so but it still looked a bit khaki so let's go to the CSS file index dot CSS and just spruce this up a little bit so first of all what I'm going to do is grab the home component then the post and then the image inside that because remember we have over here a class of container which will also give a class of home so that's the whole class right here yeah then we're looking for a post class and that thing is right here so that's going to be nested inside and then we want the image inside that alright so let's save this and go back over here so let's grab that image and then what we want to do is position this absolutely so absolute and then we'll say from the top we want it to be 20 pixels from the left we want it to be minus 100 pixels so it goes off the card to the left a bit the opacity is gonna be not 0.6 just so it fades out a little bit now let's also spell position currently and save this view it in a browser and now we can see this part of the poke ball inside the card but we also need to make this thing right here overflow:hidden so that we don't see the stuff that goes outside of the card so again let's go down here and we'll say we want the home dots post to say overflow:hidden like so and then we'll also give this oops a padding-left property and that's going to be about 80 pixels just so the pocket ball has a bit of room to breathe so let's have a look at this now alright looking better so now we have that little pocket ball on the side of each individual post now I'm just going to change the text color of this thing right here now to do that I'm going to go to our template and where we output this title right here I'm going to give this a glass of red - text so save that review this in a browser and of that is looking better all right my friends so that is how we use images in a react component
Original Description
Hey gang, in this React tutorial I'll show you how to import and use images inside your React components. We'll also tidy up a bit of the CSS.
Pokeball image - https://github.com/iamshaunjp/react-redux-complete-playlist/blob/lesson-33/poketimes/src/pokeball.png
----------------------------------------
🐱💻 Course Links:
+ VS Code editor - https://code.visualstudio.com/
+ GitHub repository (course files) - https://github.com/iamshaunjp/react-redux-complete-playlist
+ React CDN - https://reactjs.org/docs/cdn-links.html
----------------------------------------
🤑 Donate @ https://www.paypal.me/thenetninja
🎓Find me on Udemy @ https://www.udemy.com/user/47fd83f6-5e4a-4e87-a0f0-519ac51f91b6/
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
⚡
⚡
⚡
⚡
Next.js vs Remix vs SvelteKit: Which Framework Should You Learn?
Dev.to · Etrit Neziri
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
🎓
Tutor Explanation
DeepCamp AI