Skip to content

Instantly share code, notes, and snippets.

@pramendra
Last active March 6, 2018 10:05
Show Gist options
  • Save pramendra/764d6418b3e5ee93ba44735be9090753 to your computer and use it in GitHub Desktop.
Save pramendra/764d6418b3e5ee93ba44735be9090753 to your computer and use it in GitHub Desktop.

Props and cons of using create element

Overview:

  • parent has multiple items and able to sent call back to parent
  • Parent should be able to accept any type of component

with render props

https://jsbin.com/xamoyuxabi/3/edit?js,output

Disadvantages

  • get children and map it as children may have array (which may break)
  • accordion is tightly couple with renderItem making it almost impossible to reuse
  • pretty hard to communicate with parent ie sending call back

with create element

https://jsbin.com/xamoyuxabi/5/edit?js,output

with higher order component

https://jsbin.com/kuriyol/3/edit?js,output

conclusion:

with render props is pretty hard to understand and code is not dry or reusable as well as its tightly coupled component which makes its hard to reuse with different type of child.

either HOC or create element makes sense as its easy to understand and refactor.

/HOC may be harder to understand at first/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment