Skip to content

Instantly share code, notes, and snippets.

@moimikey moimikey/a.js
Created Jan 6, 2018

What would you like to do?
filter out only `on` event props from react component
// ...
renderMenu() {
const { children, } = this.props || {};
// only store props that startWith `on` in case the parent component
// wants to send event callbacks down, for subsequent use.
const eventProps = Object.keys(rest)
.filter(key => key.substr(0, 2) === 'on') // if startsWith 'on' (ie. onMouseOver)
.reduce((obj, key) => Object.assign(obj, { [key]: rest[key] }), {});
// ...

This comment has been minimized.

Copy link
Owner Author

moimikey commented Jan 6, 2018

could add an additional check to ensure that the 2nd index is an uppercase. mebe key.substr(0, 2) === 'on' && key.substr(2,1) === key.substr(2,1).toUpperCase()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.