ReactJS Tutorial – 5 – Functional Components
Video Title: ReactJS Tutorial – 5 – Functional Components
In this video let’s take a closer look at functional components functional components are just JavaScript functions they can optionally receive an object of properties which is referred to as props and return HTML which describes the UI now the HTML is actually something known as JSX but for the sake of understanding
From a beginner’s point of view let’s just call it HTML so a functional component is a JavaScript function that accepts an input of properties and returns HTML that describes the UI let’s go back to vs code and create a very first functional component to keep things simple in the app component I am
Going to remove all the HTML except the outer div tag and now let’s create our component and the component is simply going to output a message hello which was a component is nothing but a JavaScript file let’s start with that first I’m going to create a new folder called components
And within the folder I’m going to create a new file called greet dot J’s four-component file naming convention we will use Pascal case now within the file the first step is to import react so import react from react any component you create always make sure to import it next let’s create a
New function function greet and return and each one tag that says hello vishwas and that is pretty much it you have created your first functional component but as it stands now the HTML hello vishwas is not going to be rendered in the browser the grid component is in no way connected with
The rest of our application so what we have to do is export the grid function from grid gs import it in AB dot J’s and then include it in the app component so in grid gas export default grid in AB Dodgers import grid from components folder greet dot J’s file we can omit
The dot J’s extension next to include grid component in app component we simply specify the component as a custom HTML tag and if there is no content between the tags you can simply change it into a self-closing tag now if you save both the files and take
A look at the browser you should be able to see hello vishwas your first functional component is up and running now although our functional component works perfectly find the convention or reference I would say is to use arrow functions to define them so let’s rewrite the greet function with the es6
Arrow function syntax const grete is equal to mt parentheses the fat arrow syntax and then the h1 tag that says hello vishwas the syntax looks more concise than the previous approach syntax wise it also has additional advantages which we will discover as we proceed with the course
If you are new to arrow functions please get a basic understanding of how they work as we will be using them a lot throughout the series all right before we proceed to the next video I quickly want to highlight one thing about exporting and importing components please note here that we are
Exporting greet component as a default export from great chairs this is what allows us to import the component with any name I can change greet to my component and change the tag to my component and you can see that it still works as expected but in certain
Articles or videos you might also find named exports let me comment the default export and prepend the constant with the export keyword this is what is termed as a named export in this situation you have to import the component with the exact same name if I save the file you can straightaway see
That we have an error attempted import error components slash greet does not contain a default export and we are importing it as my component so you have to change the import statement to import the greet function so import within curly braces the greet constant and then
Use that as the custom HTML tag if I save this and go back to the browser you should be able to see hello which was now for most of the cases we will be using default exports but I just wanted to bring named exports to your attention
So that it can be of some help in the future let me revert back to default exports and in the next video let’s take a look at class components in react thank you guys for watching feel free to subscribe I’ll see you guys in the next one
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
thank's for this wonderful explication
Hello, can you please give me the name of your icon theme, and also the plugin you use to make the arrow display as a real icon arrow without space between the = and the > Thank you!
Hi All, Whats the difference between using a function like function Greet(){} and const Greet = function(){} ? In essence creating a function with a function KW vs storing a function in a variable?
completed 5th video. Thank you 🙂
I actually turned off ad blocker for your videos ! Really great content !
Niceee. Your just explain it too easy
Functional Components: Functional components are typically used when you have a simple component that doesn't require complex state management or lifecycle methods. They are defined as JavaScript functions and are primarily responsible for rendering UI based on the provided props. With the introduction of React Hooks, functional components can now handle state and lifecycle events as well, making them more powerful and suitable for a wider range of use cases. Functional components are often favored for their simplicity, readability, and easier testing., funtional components are not just used to render html they have some functions we can apply to html where as class components could not apply to html and render
Great explanation each and every topics of react
when I try to write the code following this tutorial to learn but I am having problems with the right frameworks installed, can you provide a complete guide for this matter.
Hi, I am getting " crbug/1173575, non-JS module files deprecated ". It was working the other day but now it's showing this.
well
Nice Job
not work.
i cant see the code of your video in App.js after entering the import Greet from './Components/Greet' .
This is the one i can see
import logo from './logo.svg';
import './App.css';
import Greet from './Components/Greet'
function App() {
return (
<div className="App">
</div>
);
}
export default App;
May I know that which version of react are you using in this tutorial??
If the arrow function doesn't work for you:
Remove the curly brackets '{ }' or use regular brackets '( )'
Because curly brackets execute code and don't return a value. Regular brackets and no brackets do.
I really hate the fat arrow bullshit. Yes Im a noob.
Thank u🙏
such a nice explanation
All React component names must start with a capital letter. So that can write in divs:
<Greet> </Greet>
There are two types of exports: Named – { }, many
and Default. – no curly, only 1 in a file. While importing can write any name (message2).
sir is it neccessary to learn first javascript before starting react???????
I save the file but it show like blank page doesn't show the hello world or something
Why Greet function has to be names same as Greet.js file, if it is diffrent it gives error?
I’m glad I searched for this. Now I can u detest and all those “react build clone videos I watch” I never knew why they were doing what they do until now Thanks ❤
Great additional information in the end.
You are answring all of my questions in the video without me asking anything. Thanks Vishwas and keep it up great work.
I think this course is no longer relevant. 4 years back this video was uploaded and now things have changed a lot. Recommend everyone to follow FreecodeCamp React course (uploaded 6 months ago) is better.
Just my opinion….
import React from 'react'
function lokesh(){
return <h1>Hello Lokesh</h1>
}
export default lokesh
import logo from './logo.svg';
import './App.css';
import React from 'react';
import lokesh from './suren.js'
function App() {
return (
<div className="App">
<lokesh />
</div>
);
}
export default App;
For the above code nothing is displayed in browser, Anyone know what mistake I have done?
i am bit confused why we need to import react in greet.js we are just making a function and exporting it
Thank god for this guy and thank you vishwas!!
Hello Sir my App component Consist Function component not Class component ,And when i changed into a class ,nothing display (UI) in Browser, Please provide solution?;…
FYI those who are searching the comments or other for an update on why the change in newer versions of React from class components to functional components (with 'Hooks') – Just continue the lesson and watch the next videos "7 – Hooks Update" has been added later and explains the changes nicely.
Thanks Vishwas! Fantastic tutorials.
you dont have to import react nowadays
I am Unable to print Hello On the Screen it iust gives a blank screen.
App.js Code
import React, {component } from 'react';
import logo from './logo.svg';
import './App.css';
import Greet from './components/Greet';
class App extends component {
render() {
return (
<div className="App">
<Greet />
</div>
);
}
}
export default App;
Greet.js code
import React from 'react'
//function Greet() {
// return <h1>Hello Devansh</h1>
//}
const Greet = () => <h1>Hello Devansh</h1>
export default Greet
Please Help
Hello everyone… For the creation of class components or functional components we can use the shortcuts offered by VsCode once the "Reactjs code snippets" extension is installed. The shortcuts are these ones:
rcc-> == class component skeleton
rsc-> == stateless component skeleton
rsf-> == stateless named function skeleton
Enjoy it!!