Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
Migrating from Class Components to Functional Components in React
Next article icon

How to Call Parent Components's Function from Child Component in React ?

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In React, it is very important to manage communication between components for building flexible and maintainable applications. Sometime, you need to trigger a function defined in a parent component from a child component. In this article, we'll see how to achieve this in React by passing down functions as props from parent to child components.

Table of Content

  • The Need for Calling Parent Functions from Child Components
  • Passing Functions as Props
  • Approach to Call Parent Component function from Child Component

The Need for Calling Parent Functions from Child Components

In React, components are arranged in a way to be modular and reusable. However, there are situations where you need to perform actions or trigger functions defined in a parent component from its child components. This can be done whenwe want to handle user interactions, update state, or executing business logic that resides in the parent component.

Passing Functions as Props

One of the core principles of React is the concept of props, which are properties passed from parent components to their children. Along with data, you can also pass functions as props from parent to child components. By doing so, child components gain access to these functions and can invoke them when necessary.

Approach to Call Parent Component function from Child Component:

  • Creating a React Application: To create a basic React Application Structure follow the Folder Structure for a React JS Project article.
  • Creating Required files: Create a file called Child.js which calls parent component's function from App.js file
  • Define Parent Function: Create a function in the parent component that you want to call from the child component.
  • Pass Function as Prop: Pass the parent function down to the child component as a prop.
  • Invoke Function in Child: In the child component, call the parent function using the prop passed down from the parent.
  • Handle Function Call: Define the logic to handle the function call in the parent component to perform desired actions.

Example: Create the files as shown in folder structure and add the following codes.

CSS
/* App.css */  * {     margin-left: 10px; }  button {     background-color: blue;     padding: 10px 15px;     color: #fff; }  .parent {     width: 27vw;     height: 22vh;     border: 1px solid black;     padding-top: 20px;     text-align: center; } 
JavaScript
//App.js   import { useState } from "react"; import "./App.css"; import Child from "./Child";  function App() {     const [showDescription, setShowDescription] = useState("");     function handleShowDescription(e) {         console.log("calling from child component");         setShowDescription(e);     }     return (         <div className="App">             <h2>Welcome to React Learning</h2>             <div className="parent">                 <h3>Parent Window</h3>                 <p>{showDescription}</p>                 <Child callFunction={handleShowDescription} />             </div>         </div>     ); }  export default App; 
JavaScript
//Child.js   function Child({ callFunction }) {      function handleClick() {         callFunction("I'm the information from child component",)     }      return (         <div>             <button onClick={(e) =>                 handleClick()}>Child Button Click</button>         </div>     ) }  export default Child; 


Output:

uichildcallparentfunctionfinal
http://loclahost:3000

Next Article
Migrating from Class Components to Functional Components in React

S

savaridevan
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • React-Props

Similar Reads

  • How To Call Function Inside Child Component From Parent Component Using useRef hook ?
    To call a function inside a child component from a parent component, first, create a useRef hook in the parent component. Then, pass this reference as a prop to the child component. In the child component, use this reference wherever needed to access or call the function from the parent. Prerequisit
    2 min read
  • Migrating from Class Components to Functional Components in React
    React version 16.8.0 or higher allows users to write the functional components without the use of class components. Using class components, we need to write the whole class to interact with the state and lifecycle of the component. The code was quite complex and harder to understand which led to low
    4 min read
  • How to convert functional component to class component in ReactJS ?
    ReactJS offers two primary ways of creating components: functional components and class components. While functional components are more concise and easier to reason about, there are situations where class components may be necessary with the flexibility to use lifecycle methods and manage the state
    2 min read
  • How to set Parent State from Children Component in ReactJS?
    To set the parent state from a child component, we use React’s unidirectional data flow. Instead of directly passing data, we pass a function that enables the child to send data back to set the parent state. Prerequisites:React JSuseState HookApproachTo set parent state from child component in React
    2 min read
  • How to communicate from parent component to the child component in Angular 9 ?
    Angular makes the communication between components very easy. In this article, we will learn how to communicate from a parent component to the child component. Approach: Let's create two components: parent child In the parent component, declare the property that you want to receive in the child comp
    2 min read
  • When to use a Class Component over a Function Component in ReactJS?
    ReactJS provides two main ways to create components: Class Components and Function Components. With the introduction of React Hooks in version 16.8, Function Components became more powerful and are now commonly preferred. However, there are still scenarios where Class Components might be a better ch
    3 min read
  • How to Pass Data From Child Component To Its Parent In ReactJS ?
    In ReactJS, the flow of data is typically one-way, meaning data is passed from parent to child components using props. However, there are situations where you may need to pass data from a child component back up to its parent component. In this article, we will cover how to pass data from a child co
    6 min read
  • How to create a Functional Component in React?
    To create a functional component in React, you define a JavaScript function that returns JSX. These components are stateless and rely on props for data input. Functional components are concise, easy to read, and can utilize React Hooks for managing state and side effects, making them a fundamental b
    2 min read
  • How to pass data from Parent to Child component in Angular ?
    We can use the @Input directive for passing the data from the Parent to Child component in Angular Using Input Binding: @Input - We can use this directive inside the child component to access the data sent by the parent component. Here app.component is the Parent component and cdetail.component is t
    3 min read
  • How to Pass Data from One Component to Another Component in ReactJS?
    In ReactJS, components are the building blocks of your user interface. Components allow you to create modular, reusable UI elements, but sometimes these components need to communicate with each other. In this article, we will explore the different methods to pass data between components in ReactJS.
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences