Use functions instead of classes to define JavaScript components
See original GitHub issueThis requires a major overhaul but would greatly simplify component definitions. Not having to worry about the context of this
would ease understanding of how components work and bolster confidence when adding features or items. There are performance-related worries but it looks like those do not translate to real world use cases. React hooks are created using functions and have been adopted without major issues.
As I said, this would be a major undertaking so I was not able to make a pull request but a functional component would resemble existing ones minus the this
keyword.
function Alert(element) {
...
function close(element) {
const rootElement = element ? _getRootElement(element) : _element
const customEvent = _triggerCloseEvent(rootElement)
if (customEvent === null || customEvent.defaultPrevented) {
return
}
_removeElement(rootElement)
}
...
}
Here are some articles that explore this subject in greater detail: https://css-tricks.com/the-flavors-of-object-oriented-programming-in-javascript/ https://www.toptal.com/javascript/es6-class-chaos-keeps-js-developer-up
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
Yes, I completely understand. Whenever you are willing to make the change, just let me know. I will be happy to help you guys out. In the meantime, I will try to contribute by fixing other issues.
@jjoel1630 You can contribute by helping with any of the open issues or by submitting for review your own code implementing some feature.