Skip to content

Instantly share code, notes, and snippets.

@jhonsore
Last active July 9, 2019 18:10
Show Gist options
  • Select an option

  • Save jhonsore/05ab9eab97d87509631e69388ea98889 to your computer and use it in GitHub Desktop.

Select an option

Save jhonsore/05ab9eab97d87509631e69388ea98889 to your computer and use it in GitHub Desktop.
Reactjs Tipps
//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>
}
//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