Table of Contents
Parent Child Component Communication in React
What we have learned so far?
Part 1 – Hello Word in React?
https://onlyfullstack.blogspot.com/2019/11/create-reactjs-app-hello-world.html
Part 2 – JSX in React
https://onlyfullstack.blogspot.com/2019/11/jsx-in-react.html
https://onlyfullstack.blogspot.com/2019/11/react-components-state-props-lifecycle.html
Part 4 – Event Handling in React
https://onlyfullstack.blogspot.com/2019/11/event-handling-in-react.html
Parent to Child component communication in React
1. React props
We can use props to do the communication in between Parent and child component in React.
import React from 'react'; export default function Child(props) { return <h1>Hello, {props.name}</h1>; }
Child to Parent component communication in React with callback
We can give callback to child component to do the communication from child to parent. In below example we have given a callback named as handleCloseWithCallback.
we can call that method with the passed prop name to send any data to parent component from child component.
export default function Child(props) { return ( <div> <h2>Child to parent component communication</h2> <h3>Hello, {props.name}</h3> <button onClick={() => props.handleCloseWithCallback("childprop")}> Close with callback </button> </div> ); }
Lets go to our next tutorial where we will discuss below points :
Part 6 – React Forms with Input text, Checkbox, Radio Buttons and Dropdown
– React Form with Input text
– React Form with Checkbox
– React Form with Radio Button
– React Form with Dropdown list
https://onlyfullstack.blogspot.com/2019/11/react-forms-with-input-checkbox-radiobutton-dropdown.html
Source Code
You can edit and play with the react examples on below stackblitz site –
https://stackblitz.com/@onlyfullstack
React Tutorial
https://onlyfullstack.blogspot.com/2019/11/react-tutorial.html