Last active
October 20, 2017 20:33
-
-
Save dounan/d3ccda7977e34b93ad6b6929e0e8129d to your computer and use it in GitHub Desktop.
Example of hoisting an arrow function with reflective-bind
This file contains 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
// ====================================================== | |
// 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