Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Nav extends React.Component {
- constructor() {
- super();
- this.onNav = this.onNav.bind(this);
- }
- onNav(idx) {
- // do something with `this` and `idx`
- }
- render() {
- return (
- <ul>
- {btns.map((btn, i) => <Button key={btn} onClick={this.onNav} idx={i}>{btn}</Button>)}
- </ul>
- );
- }
- }
- class Button extends React.Component {
- shouldComponentUpdate(nextProps) {
- return !shallowEqual(nextProps, this.props);
- }
- render() {
- const { onClick, idx, children } = this.props;
- return <button onClick={() => onClick(idx)}>{children}</button>;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement