Skip to content

Instantly share code, notes, and snippets.

@monteslu
Created January 10, 2018 23:10
Show Gist options
  • Save monteslu/ce7c8bf5f2d81e60038ec9a1af7feea9 to your computer and use it in GitHub Desktop.
Save monteslu/ce7c8bf5f2d81e60038ec9a1af7feea9 to your computer and use it in GitHub Desktop.
stupid hack
import React from 'react';
import { connect } from 'react-redux';
import { show, hide } from '../state/menu';
class CoolComponent extends React.Component {
addActions ( actions ) {
actions.forEach((action) => {
this[action] = (a,b,c,d,e,f,g) => {
this.props[action].apply(this, [a,b,c,d,e,f,g]);
}
})
}
}
class Menu extends CoolComponent {
constructor () {
super();
this.addActions(['show', 'hide']);
}
render () {
const { menu } = this.props;
console.log('render menu', this.props);
return (
<div>
<button onClick={this.show}>Trigger Modal</button>
<button onClick={this.hide}>Close Modal</button>
stuff
</div>
);
}
}
const ConnectedMenu = connect((state) => {
const { menu } = state;
return { menu };
}, { show, hide })(Menu);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment