Last active
October 5, 2016 18:07
-
-
Save malte-wessel/6a9ab5def723d6818897c626ec5550a0 to your computer and use it in GitHub Desktop.
Melody with React/Inferno: Refs
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 { createComponent } from 'melody-component'; | |
import template from './template.twig'; | |
export default createComponent({ | |
componentDidMount() { | |
this.refs.button.addEventListener('click', this.handleClick); | |
}, | |
componentWillUnmount() { | |
this.refs.button.removeEventListener('click', this.handleClick); | |
} | |
template: template | |
}); |
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 { createClass } from 'react'; | |
export default function createComponent(definition) { | |
const { template, ...rest } = definition; | |
if (!template) throw new Error('Please provide a template.'); | |
return createClass({ | |
...rest, | |
render() { | |
return template(this.props); | |
} | |
}); | |
} |
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
<div class="box"> | |
<button ref="button">Click me</button> | |
</div> |
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
// Compiled twig template | |
export default function(props) { | |
return ( | |
<div className="box"> | |
<button ref="button">Click me</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment