reactjs - React: call parent version of the functiion when overriding -


when i'm overriding function in child class, how can call parent version of function?

say have 2 components abstractlist , sortablelist in react with:

class abstractlist extends react.component {   getitems() {     ...   } }  class sortablelist extends abstractlist {   getitems() {     ... sorting first     return super.getitems(); // question: how supported this?   } } 

thanks!

you should not way

check issue on github

many people have become accustomed using oo inheritance not tool, primary means of abstraction in application. i've you've worked @ java shop, you'll know i'm talking about. in personal opinion, classical oo inheritance (as implemented in many popular languages) not best tool jobs, let alone jobs. situation should approached more caution when inheritance used within framework or paradigm uses functional composition primary abstraction (react). there patterns we'll want prevent (there many strange things people can come when combining render inheritance don't make sense , addressed via simple composition). there's risk of making mutation more convenient. might make sense start es6 classes better syntax react component creation, intentionally limiting use cases (limiting inheritance depth, making react base class methods final) (only when used react components of course - non-react use of es6 classes wouldn't restricted).

instead of this

class abstractlist extends react.component {   getitems() {     ...   } }  class sortablelist extends abstractlist {   getitems() {     ... sorting first     return super.getitems();    } } 

you should do

class abstractlist extends react.component {   getitems() {     ...   } }  class sortablelist extends react.component {   render() {       return <abstractlist items={this.props.item}>{this.props.children}</abstractlist>;   } } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -