Last active
July 9, 2019 18:10
-
-
Save jhonsore/05ab9eab97d87509631e69388ea98889 to your computer and use it in GitHub Desktop.
Reactjs Tipps
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
| //utils.js | |
| import React from 'react' | |
| export function childrenWithProps (props) { | |
| return React.children.map(props.children, child => { | |
| return React.CloneElement(child, { ...props }); | |
| }); | |
| } | |
| //------ | |
| //family.js | |
| import React from 'react'; | |
| import { childrenWithProps } from 'utils.js' | |
| export default props => <div>{childrenWithProps(props)}</div>; | |
| //------ | |
| import React from 'react'; | |
| import Family from 'family'; | |
| export default () => { | |
| <Family myPropTosend="my value"> | |
| <Kid name='Name 1' /> | |
| <Kid name='Name 2' /> | |
| </Family> | |
| } |
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
| //Method 01 | |
| func () => { | |
| console.log(this); | |
| } | |
| //Method 02 | |
| function myFunc(){ | |
| console.log(this); | |
| } | |
| <button onClick={()=>this.myFunc()}></button> | |
| //Method 03 | |
| this.bind = this.myFunc.bind(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment