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}
/>
)}
</>
);
};
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
const root = ReactDOM.createRoot(document.getElementById('root'));
const element = <Welcome name="Sara" />;
root.render(element);
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