Skip to content

Instantly share code, notes, and snippets.

@dounan
Last active October 20, 2017 20:33
Show Gist options
  • Save dounan/d3ccda7977e34b93ad6b6929e0e8129d to your computer and use it in GitHub Desktop.
Save dounan/d3ccda7977e34b93ad6b6929e0e8129d to your computer and use it in GitHub Desktop.
Example of hoisting an arrow function with reflective-bind
// ======================================================
// Original code
function MyComponent(props) {
const msg = "Hello " + props.user.name.first;
return <PureChild onClick={() => alert(msg)} />
}
// ======================================================
// After reflective-bind/babel transforms the code
function _hoisted(_temp) {
alert(_temp);
}
function MyComponent(props) {
const msg = "Hello " + props.user.name.first;
return <PureChild onClick={reflectiveBind(_hoisted, this, msg)} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment