Home > Web Front-end > JS Tutorial > How to pass information from a child element back to its parent

How to pass information from a child element back to its parent

Patricia Arquette
Release: 2024-12-12 17:25:13
Original
392 people have browsed it

In this example, you are going to create a simple parent and child element combination that passes some simple data back from the child element through a function parameter.


  • Make a simple child element first with a input element with the onChange property to update a localized state variable to its current value.

How to pass information from a child element back to its parent

  • This is the barebones element, and needs to have the functionality of passing back to its parent element. Below our additions to the element including adding a new button to "Send Data" to its parent with the onClick pointing to a local function that calls a function that is now passed into this child element.

How to pass information from a child element back to its parent

  • Next step is to make the parent element which uses a simple state variable to hold the data returned, and a local function that is called from the child. The data that is being returned from the child function is passing upwards to its 'handler' - handleDataFromChild() and then being set inside our local state variable. This data is now accessible throughout this parent element.

How to pass information from a child element back to its parent


Thank you so much for taking the time to read, and dont forgot to follow along my learning journey here on dev.to, and comment anything new I should be looking into with the React world!

The above is the detailed content of How to pass information from a child element back to its parent. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template