Last active
November 10, 2020 21:15
-
-
Save ianks/f1d8cc09b7f854212274637fd0d55064 to your computer and use it in GitHub Desktop.
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
export class UserList extends React.Component { | |
handleClick = (item) => console.log('You clicked ', this.props.group); | |
render() { | |
return ( | |
<HugeListOfItems | |
group={group} | |
handleClick={this.handleClick} | |
/> | |
); | |
} | |
} |
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
export function UserList({ group }) { | |
// Have to remember to useCallback here to avoid | |
// the function getting recreated. | |
const handleClick = useCallback(item => { | |
console.log('You clicked ', group); | |
// Have to pass all of the variable references here so | |
// React knows when to update the callback function. | |
}, [group]); | |
return ( | |
<HugeListOfItems | |
group={group} | |
handleClick={handleClick} | |
/> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment