Created
May 7, 2019 22:46
-
-
Save mattheu/d4756e69a5304c3f609e53001ea04c6c 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
import withUniqueId from './with-unique-id'; | |
function FormField({ | |
id, | |
label, | |
value, | |
onChange, | |
}) { | |
return ( | |
<div> | |
<label for={ `field-${ id }` }>{ label }</label> | |
<input id={ `field-${ id }` } type="text" value={ value } onChange={ onChange }/> | |
</div> | |
); | |
} | |
export withUniqueId( FormField ); |
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
export function withUniqueId( WrappedComponent ) { | |
return class extends React.Component { | |
constructor( props ) { | |
super( props ); | |
this.id = _.uniqueId(); | |
} | |
render() { | |
return ( | |
<WrappedComponent | |
{ ...this.props } | |
id={ this.id } | |
/> | |
); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment