Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement to Function as Prop Component #7

Open
TonyGravagno opened this issue Jan 27, 2023 · 0 comments
Open

Enhancement to Function as Prop Component #7

TonyGravagno opened this issue Jan 27, 2023 · 0 comments

Comments

@TonyGravagno
Copy link

The initial text is understandable, but I recommend a different approach:

Replace

Exactly passing a render callback function to a component is not the issue. The issue is the function as child component implementation chose to use the prop children.

So how could you pass a render callback function to a component in a clean manner?

You would need to name your prop meaningful.

with

Passing a render callback using the function as child component pattern is very common. But that approach is limited, in that there is only one 'children' property in the component. A cleaner and more versatile approach is to pass functions to the component as named props.

This is how common element events are handled, with props-as-attributes like onclick, and onchange, and onsubmit.

Here is an example with a named property passing a function in-line to the Foo component:

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant