salsita / prism

React / Redux action composition made simple http://salsita.github.io/prism/
495 stars 24 forks source link

Props 'selector' and 'wrapper' get passed down to enhanced component #78

Closed dvshur closed 7 years ago

dvshur commented 7 years ago

Hi,

I noticed that in current implementation of enhanceComponent the enhanced (inner) component receives prism-specific props selector and wrapper. For me it caused a problem with a 'controlled input' component where props got passed down further by something like { ...rest } to native HTML tag, causing a React Warning: Unknown props `selector`, `wrapper` on <input> tag..

As far as I understand, those props are only used to patch a store in getChildContext, and the inner component doesn't need them, so I believe they should stay in the wrapping EnhancedComponent.

Right now a render method of enhanceComponent looks like this:

render() {
    return createEagerElement(
        EnhanceableComponent,
        this.props
    );
}

To stop passing down those props, something like this could be done instead:

render() {
    const {
        selector,
        wrapper,
        ...rest
    } = this.props;

    return createEagerElement(
        EnhanceableComponent,
        rest
    );
}

What do you think about it?

dvshur commented 7 years ago

@tomkis could you please take a look?

I could submit a PR if you think this is a right idea.

dvshur commented 7 years ago

@tomkis thank you for fixing the issue, but could you please publish the fix to npm?

tomkis commented 7 years ago

@dvshur apologies, I totally forgot to publish the change. Should be fixed in prism@4.1.2