Last active
August 28, 2018 01:14
-
-
Save shqld/4bf8ea2fcee159a74b5b13d23a0d71a8 to your computer and use it in GitHub Desktop.
Setting element attributes dynamically
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
/* withAttr.jsx */ | |
import React from 'react' | |
const withAttr = (Component) => ({attrs, ...props}) => <Component {...attrs} {...props} /> | |
export default withAttr | |
/* example.jsx */ | |
import React from 'react' | |
import withAttr from './withAttr' | |
const SomeComponent = ({isSomeAttr}) => <div attrs={{ 'data-some-attr': isSomeAttr }} /> | |
export default withAttr(SomeComponent) | |
// Will be rendered like | |
<div data-some-attr="true"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment