A Pen by K.C.Ashish Kumar on CodePen.
Last active
April 2, 2020 22:01
-
-
Save kcak11/49995ae636b191a16621738d07172c5f to your computer and use it in GitHub Desktop.
A Simple HOC
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
<div id="app"></div> |
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
const { Fragment } = React; | |
const MyHOC = function (InputComponent) { | |
let myCustomProps = { | |
style: { | |
color: "red", | |
"font-family": "Verdana", | |
"font-size": "20px" | |
}, | |
onClick: function () { | |
alert("You clicked this button"); | |
} | |
}; | |
return function (props) { | |
return <InputComponent {...props} {...myCustomProps} />; | |
}; | |
}; | |
const App = function () { | |
let MyButton = MyHOC("button"); | |
return ( | |
<Fragment> | |
<span>A Simple Button</span> | |
<br /> | |
<button>click me</button> | |
<br /><br/> | |
<span>A HOC Button</span> | |
<br /> | |
<MyButton>click me</MyButton> | |
</Fragment> | |
); | |
}; | |
ReactDOM.render(<App />, document.getElementById("app")); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment