function App() {
const [status, setStatus] = React.useState(false);
const [text, setText] = React.useState("");
const handleClick = () => {
this.setStatus(prev => ({ status: !prev.status }));
};
const handleChange = e => {
this.setStatus({ text: e.target.value });
};
return (
<>
<button onClick={handleClick}>Open photo entry dialog</button>
<ChildComponent
isOpen={status}
text={text}
handleChange={handleChange}
handleClick={handleClick}
/>
</>
);
}
const ChildComponent = ({ isOpen, text, handleChange, handleClick }) => {
return (
<>
{isOpen && (
<Model
status={isOpen}
handleClick={handleClick}
text={text}
handleChange={handleChange}
/>
)}
</>
);
};
const Banner = props => {
const name = props.name
return (
<div>
<p>Hello {name}</p>
<button onClick={props.clickHandler}>Click Me</button>
</div>
)
}
function App() {
const showAlert = () => {
alert("Welcome!")
}
return (
<div>
<Banner name="Ranjeet" clickHandler={showAlert} />
</div>
)
}
export default App
import React from 'react';
import './App.css';
import NewComponent from './components/NewComponent';
// import NewFunctionalComponent from './components/NewFunctionalComponent';
class App extends React.Component {
constructor(){
super()
this.state = {
isClicked: false
}
console.log(this.state)
}
handleClick = () => {
console.log('I have been clicked')
this.setState({
isClicked: true
}, () => console.log(this.state.isClicked))
}
render() {
return (
<div className="App">
<NewComponent clickMe={this.handleClick} />
{/* <NewFunctionalComponent noClickMe={this.handleClick} /> */}
</div>
)
}
}
export default App;