A
A
Amir2017-03-22 11:35:36
React
Amir, 2017-03-22 11:35:36

Is it possible and how to use inheritance in React?

Good afternoon, dear connoisseurs. The question is:
Is it possible to inherit components from each other in React? It turns out that almost every component has a method:

componentWillReceiveProps(nextProps) {
    if (nextProps.val != this.state.val) {
        this.setState({val: nextProps.val});
    }
}

It turns out terrible duplication of code. Is there any way to avoid this? As far as I understand Google, it’s impossible (there is something about mixins, but it’s not clear to me yet). Can you push me in the right direction?
Thanks in advance for the replies.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2017-03-22
@Guedda

Higher Order Component

I
imdeveloper, 2017-03-22
@link_web

Higher Order Components

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question