I am working on a React project, In my project I have two components those are App and Child. The app is Parent component and child is Child component.
Now I Changed state in Child component when I click the button on Child component.
Now my goal is how to pass latest state of the Child component for a Parent component button.
I am not getting how to do this, please help me
This is App.js
import React from 'react';
import './App.css';
import Child from './Child/Child';
function App() {
return(
<div className='container'>
<div className='row'>
<button className='btn btn-primary'>Click here</button>
<Child></Child>
</div>
</div>
)
}
export default App
This is Child.js
import React, { useState } from 'react';
import './Child.css';
function Child() {
const [color, setColor] = useState('yellow');
const [textColor, setTextColor] = useState('white');
return (
<div className='container'>
<div className='row'>
<button style={{ background: color, color: textColor }}
onClick={()=>{setColor("black");setTextColor('red')}}className='btn btn-danger mt-5'>Click here</button>
</div>
</div>
)
}
export default Child
If you feel that I am not clear with my doubt, please put a comment. Thank you.