Skip to content

Instantly share code, notes, and snippets.

@ianks
Last active November 10, 2020 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianks/f1d8cc09b7f854212274637fd0d55064 to your computer and use it in GitHub Desktop.
Save ianks/f1d8cc09b7f854212274637fd0d55064 to your computer and use it in GitHub Desktop.
export class UserList extends React.Component {
handleClick = (item) => console.log('You clicked ', this.props.group);
render() {
return (
<HugeListOfItems
group={group}
handleClick={this.handleClick}
/>
);
}
}
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