Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. class Nav extends React.Component {
  2. constructor() {
  3. super();
  4. this.onNav = this.onNav.bind(this);
  5. }
  6. onNav(idx) {
  7. // do something with `this` and `idx`
  8. }
  9. render() {
  10. return (
  11. <ul>
  12. {btns.map((btn, i) => <Button key={btn} onClick={this.onNav} idx={i}>{btn}</Button>)}
  13. </ul>
  14. );
  15. }
  16. }
  17.  
  18. class Button extends React.Component {
  19. shouldComponentUpdate(nextProps) {
  20. return !shallowEqual(nextProps, this.props);
  21. }
  22. render() {
  23. const { onClick, idx, children } = this.props;
  24. return <button onClick={() => onClick(idx)}>{children}</button>;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement