Created
April 19, 2020 23:06
-
-
Save jsmanifest/9a4c10ba6770c8f6248a9885b1511de1 to your computer and use it in GitHub Desktop.
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
function AppContent({ onChange }) { | |
const [value, setValue] = React.useState('') | |
function handleOnChange(e) { | |
if (onChange) { | |
onChange(function({ person, collapsed }) { | |
console.log(collapsed) | |
console.log(person) | |
setValue(e.target.value) | |
}) | |
} | |
} | |
return ( | |
<input placeholder="Your value" value={value} onChange={handleOnChange} /> | |
) | |
} | |
function App() { | |
const [collapsed, setCollapsed] = React.useState(true) | |
function onChange(callback) { | |
const person = collapsed ? null : { name: 'Mike Gonzalez' } | |
callback({ person, collapsed }) | |
} | |
return ( | |
<div> | |
<AppContent | |
onChange={(cb) => { | |
setCollapsed(false) | |
onChange(cb) | |
}} | |
/> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment