0
Я пытаюсь расширить компонент и переопределить один метод, но оба этих метода не работают.Как создать активный компонент базы, который я могу расширить?
var Hello = React.createClass({
getName: function() { throw "This method not implemented" },
render: function() {
return <this.props.component.slug className='text'>
{this.props.component.value}{this.getName()}
</this.props.component.slug>;
}
});
class HelloChild extends Hello {
constructor(props) {
super(props);
}
getName()
{
return "Child";
}
};
Вторая попытка:
class Hello extends React.Component {
getName() { throw "This method not implemented" }
render() {
return <this.props.component.slug className='text'>
{this.props.component.value}{this.getName()}
</this.props.component.slug>;
}
};
class HelloChild extends Hello {
constructor(props) {
super(props);
}
getName()
{
return "Child";
}
};
Когда я пытаюсь оказать HelloChild, он выдает ошибку:
Uncaught Invariant Violation: Objects are not valid as a React child
(found: object with keys {}). If you meant to render a collection of
children, use an array instead or wrap the object using
createFragment(object) from the React add-ons. Check the render method
of `bound `.
Как продлить его и только переопределить один метод?
нет. он работает, если я просто выполняю компонент Hello –
, как насчет добавления 'this.getName = this.getName.bind (this)' в конструктор функции Hello Component. – chenkehxx