This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve fromRenderProps #702
Comments
Considering providing a more general solution, we can change the third argument of
to
As a result we can use it like const EnhancedComponent = fromRenderProps(
RenderPropComponent,
({ text }) => ({ text }),
({ name, children }) => ({ name, children }) // or just an identity function
)(component); However, in my opinion const EnhancedComponent = fromRenderProps(
({ name, children }) => <RenderPropComponent name={name} children={children} />,
({ text }) => ({ text })
)(component); is good enough currently :) |
Actually I really like your idea to change
As it would be more explicit on which props are sent to the renderProp component, and we won't risk to overload an outter |
This way my example would change to: const RenderPropComponent = ({ name, children }) => children({ text: `Hello ${name}!` });
const component = ({ text }) => <h1>{text}</h1>;
const EnhancedComponent = fromRenderProps(
RenderPropComponent,
({ text }) => ({ text }),
({ name }, children) => ({ name, children })
// or:
// (children, { name }) => ({ name, children })
)(component);
<EnhancedComponent name="John" />
// Would render <h1>Hello John!</h1> |
Any update about this issue ? If anyone is ok with it I could easily submit a PR ! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The new feature
fromRenderProps
looks really nice, but I think it would be even better if we could send props to the inner renderProp component like that:It would be as simple as adding
...ownerProps
to fromRenderProps.js (L14):I deal with a lot of "render prop" components, and I won't be able to use
fromRenderProps
with most of them until such a change has been made.What do you think about that ? I will be more than happy to send a PR if needed !
The text was updated successfully, but these errors were encountered: