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

Try using createElement for renderAppender render prop #15259

Merged
merged 2 commits into from
May 3, 2019

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Apr 30, 2019

Description

This PR serves as an iteration on #14241 and #14943.

As mentioned in a couple of comments by @aduth, using createElement instead of the traditional function call when rendering a render prop offers more flexibility for the implementor of the render prop. The implementor can use the traditional render prop style:

renderAppender={ () =>  ( <MyComponent /> ) }

as well as using a simpler style without the need for the wrapping function:

renderAppender={ MyComponent }

The only downside I can see is that if parameters were added to renderAppender, they'd need to be expressed as props:

renderAppender={ ( { someParam } ) => ( <MyComponent someProp={ someParam } /> ) }

instead of a plain argument:

renderAppender={ ( someParam ) => ( <MyComponent someProp={ someParam } /> ) }

which is inconsistent with other render props.

How has this been tested?

  1. Create a Group Block
  2. Observe that the button appender is initially rendered
  3. Click the button appender and add an image block to the group block
  4. Observe that button appender is no longer shown and a trailing appender is displayed after the image block
  5. Add a paragraph to the group block
  6. Observe that no trailing appender (or button appender) is shown in the group block (the user can press 'enter' to add another block.)

Types of changes

Non-breaking refactor

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@talldan talldan added [Type] Task Issues or PRs that have been broken down into an individual action to take [Block] Group Affects the Group Block labels Apr 30, 2019
@talldan talldan self-assigned this Apr 30, 2019
return (
<div className="block-list-appender">
{ createElement( renderAppender ) }
<CustomAppender />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth - this is another alternative since JSX desugars to createElement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth - this is another alternative since JSX desugars to createElement.

I hadn't thought about that, but yes, I think that'd make for a fine (preferred) alternative.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice simple improvement 👍 Thanks for running with it.

@talldan talldan merged commit 5c48dc1 into master May 3, 2019
@talldan talldan deleted the try/create-element-render-appender branch May 3, 2019 02:20
@talldan talldan added this to the 5.7 (Gutenberg) milestone May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Group Affects the Group Block [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants