src/App.js
import './App.css';
import ParentComponent from './components/ParentComponent';
function App() {
return (
<div className="App">
<p><b>App.js</b> |function|</p>
<ParentComponent/>
</div>
);
}
export default App;
src/App.js
.App{
background-color: lightskyblue;
padding: 10px 10px;
}
p{
margin-top: 6px;
margin-bottom: 12px
}
src/components/ParentComponent.jsx
import React, { useState } from "react"
import ChildComponent from "./ChildComponent"
import "./ParentComponent.css"
function ParentComponent(){
const[backgroundColor, setBackgroundColor] = useState('pink');
const handleInputChange = (event) => {
setBackgroundColor(event.target.value);
}
return(
<div className="ParentComponent" style={{backgroundColor: backgroundColor}}>
<p><b>ParentComponent.jsx</b> |function|</p>
<ChildComponent handleInputChange={(event)=>{handleInputChange(event)}} />
</div>
)
}
export default ParentComponent
src/components/ParentComponent.css
.ParentComponent{
background-color: lightsalmon;
padding: 10px 10px;
margin: 10px 10px;
}
h2{
margin-top: 0px;
margin-bottom: 6px
}
src/components/ChildComponent.jsx
import React from "react";
import "./ChildComponent.css"
function ChildComponent(props){
const handleChange = (event) => {
props.handleInputChange(event);
}
return (
<div className="ChildComponent">
<p><b>ChildComponent.jsx</b> |function|</p>
<input onChange={(event)=>{handleChange(event)}}></input>
</div>
);
}
export default ChildComponent;
src/components/ChildComponent.css
.ChildComponent{
background-color: lightgreen;
padding: 10px 10px;
margin: 10px 10px;
}
h3{
margin-top: 0px;
margin-bottom: 6px
}
Top comments (0)