Created
February 27, 2023 01:57
-
-
Save dcortesnet/34651aa0e8db5663d6df71fc6aa21084 to your computer and use it in GitHub Desktop.
Reactjs smart component y dump component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Smart Component | |
| import React, { useState } from 'react'; | |
| import DumpComponent from './DumpComponent'; | |
| const SmartComponent = () => { | |
| const [name, setName] = useState(''); | |
| const handleInputChange = (e) => { | |
| setName(e.target.value); | |
| }; | |
| const handleButtonClick = () => { | |
| alert(`Hello, ${name}!`); | |
| }; | |
| return ( | |
| <DumpComponent | |
| name={name} | |
| onInputChange={handleInputChange} | |
| onButtonClick={handleButtonClick} | |
| /> | |
| ); | |
| }; | |
| export default SmartComponent; | |
| // Dump Component | |
| import React from 'react'; | |
| const DumpComponent = ({ name, onInputChange, onButtonClick }) => { | |
| return ( | |
| <div> | |
| <input type="text" value={name} onChange={onInputChange} /> | |
| <button onClick={onButtonClick}>Say Hello</button> | |
| </div> | |
| ); | |
| }; | |
| export default DumpComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment