Functional Components in React
Learn how to create, reuse and compose functional components with practical examples from CIIT Training Institute.
01 Learning Objectives
After completing this lesson, you will be able to:
Write components using functions and arrow functions.
Return headings, paragraphs, lists and other UI elements.
Pass student names and course details to components.
Build reusable UI instead of repeating the same code.
02 What Is a Functional Component?
A Functional Component is a JavaScript function that returns React elements, usually written using JSX. Component names should begin with an uppercase letter.
<Welcome />.
function Welcome() {
return (
<div>
<h2>Welcome to CIIT Training Institute!</h2>
<p>Learn React step by step.</p>
</div>
);
}
export default Welcome;
import Welcome from "./Welcome";
function App() {
return (
<main>
<Welcome />
</main>
);
}
export default App;
Welcome to CIIT Training Institute!
Learn React step by step.
03 Functional Component Flow Diagram
The parent component App can render child components.
Each component is responsible for returning its own UI.
function Header() {
return <h2>CIIT Training Institute</h2>;
}
function CourseList() {
return (
<ul>
<li>React JS</li>
<li>.NET Full Stack</li>
<li>Python</li>
</ul>
);
}
function Footer() {
return <p>Learn. Practice. Build Projects.</p>;
}
function App() {
return (
<div>
<Header />
<CourseList />
<Footer />
</div>
);
}
export default App;
CIIT Training Institute
- React JS
- .NET Full Stack
- Python
Learn. Practice. Build Projects.
04 Function Declaration vs Arrow Function
React functional components can be written using either a function declaration or an arrow function.
Function Declaration
function StudentOne() {
return (
<p>Student: Samadhan</p>
);
}
export default StudentOne;
Student: Samadhan
Arrow Function
const StudentTwo = () => {
return (
<p>Student: Samiksha</p>
);
};
export default StudentTwo;
Student: Samiksha
05 Functional Components with Props
Props are used to pass data from a parent component to a child component. The same component can display different student information without duplicating its structure.
function StudentCard({ name, course }) {
return (
<div>
<h3>{name}</h3>
<p>Course: {course}</p>
</div>
);
}
export default StudentCard;
import StudentCard from "./StudentCard";
function App() {
return (
<div>
<h2>CIIT Student Profiles</h2>
<StudentCard
name="Samadhan"
course="React JS"
/>
<StudentCard
name="Samiksha"
course=".NET Full Stack"
/>
<StudentCard
name="Pradnya"
course="Python"
/>
</div>
);
}
export default App;
CIIT Student Profiles
06 Component Composition
Component composition means combining smaller components to create a larger UI. It makes React applications easier to organize and maintain.
function CourseTitle() {
return <h2>React JS Training</h2>;
}
function CourseDetails() {
return (
<p>
Learn components, JSX and props at CIIT Training Institute.
</p>
);
}
function CourseSection() {
return (
<section>
<CourseTitle />
<CourseDetails />
</section>
);
}
function App() {
return <CourseSection />;
}
export default App;
React JS Training
Learn components, JSX and props at CIIT Training Institute.
07 Important Rules and Best Practices
Start component names with an uppercase letter.
Return one parent JSX element or use a Fragment.
Use props to pass data into reusable components.
Keep components focused on a clear responsibility.
Call React Hooks only at the top level of components or custom Hooks.
08 Practice Questions
- Create a functional component named
InstituteInfo. - Create an arrow-function component that displays your name.
- Create a reusable
StudentCardusing name and course props. - Display Samadhan, Samiksha and Pradnya using one reusable component.
- Create a parent component that renders Header, CourseList and Footer.
- Build a course section by composing two smaller components.
Summary
Functional Components are JavaScript functions that return React elements and form the building blocks of a React application. They can be written as function declarations or arrow functions. Props allow components to receive data, while component composition combines smaller UI elements into a complete page. At CIIT Training Institute, practise these concepts by creating reusable components for student profiles, course lists and training information.