Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Created September 7, 2020 10:21
Show Gist options
  • Save indreklasn/f56e02d10f188b1a9ac2a904ace8125f to your computer and use it in GitHub Desktop.
Save indreklasn/f56e02d10f188b1a9ac2a904ace8125f to your computer and use it in GitHub Desktop.
// hidden-message.js
import React from 'react'
// NOTE: React Testing Library works well with React Hooks and classes.
// Your tests will be the same regardless of how you write your components.
function HiddenMessage({children}) {
const [showMessage, setShowMessage] = React.useState(false)
return (
<div>
<label htmlFor="toggle">Show Message</label>
<input
id="toggle"
type="checkbox"
onChange={e => setShowMessage(e.target.checked)}
checked={showMessage}
/>
{showMessage ? children : null}
</div>
)
}
export default HiddenMessage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment