Created
January 29, 2023 10:22
-
-
Save Lahirutech/311f4a349957a2ddd5aae122b5d9cb19 to your computer and use it in GitHub Desktop.
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 React from 'react'; | |
| const withNewProp = (WrappedComponent) => { | |
| const [count, setCount] = React.useState(0); | |
| return (props) => { | |
| return ( | |
| <WrappedComponent | |
| {...props} | |
| newProp='add many props' | |
| count={count} | |
| setCount={setCount} | |
| /> | |
| ); | |
| }; | |
| }; | |
| const MyComponent = (props) => { | |
| return ( | |
| <div> | |
| {props.newProp}+ {props.count} | |
| </div> | |
| ); | |
| }; | |
| const EnhancedMyComponent = withNewProp(MyComponent); | |
| export default EnhancedMyComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment