Skip to content

Instantly share code, notes, and snippets.

@shqld
Last active August 28, 2018 01:14
Show Gist options
  • Save shqld/4bf8ea2fcee159a74b5b13d23a0d71a8 to your computer and use it in GitHub Desktop.
Save shqld/4bf8ea2fcee159a74b5b13d23a0d71a8 to your computer and use it in GitHub Desktop.
Setting element attributes dynamically
/* 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