Let’s say we have
class OriginalComponent extends Component {
// various code..
someFunction = () => {
// does stuff
}
}
I want to get the functionality of OriginalComponent
but with the change that someFunction
is replaced with different functionality.
I can think of two possible ways to do this:
- Define
NewComponent
through inheritance:
class NewComponent extends OriginalComponent {
// various code..
someFunction = () => {
// does new stuff
}
}
- Directly change the
prototype
onOriginalComponent
:
OriginalComponent.prototype.methodName = function()
{
// does new stuff
}
Do both of these methods work? Do they differ? What is recommended here.
I am using a third party library that allows me to pass in overrides for particular React components in the config, for context.