Created
November 23, 2017 16:10
-
-
Save worst-developer/f74e0a04864a48343b003e7253cffba8 to your computer and use it in GitHub Desktop.
React-recompose checkbox
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
import React from 'react'; | |
import { compose, withState, withHandlers } from 'recompose'; | |
const Checkbox = ({ isChecked, handleClick }) => ( | |
<input | |
type="checkbox" | |
checked={isChecked} | |
onClick={handleClick} | |
/> | |
); | |
export default compose( | |
withState('isChecked', 'handleClick', false), | |
withHandlers({ | |
handleClick: props => () => { | |
props.handleClick(!props.isChecked); | |
props.handleCheckbox(!props.isChecked); | |
} | |
}) | |
)(Checkbox); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment