У меня есть два компонента. В зависимости от условия в контейнере рендюрю один из нихНо логика у этих компонентах повторяется Особенно метод componentWillReseiveProps у них одинаковый и выглядит примерно так
componentWillReceiveProps(nextProps) {
const { inputType: nextInputType } = nextProps;
const { inputType, values } = this.props;
const { message: nextMessage } = this.getDefaultValues(nextProps.values);
const { message } = this.getDefaultValues(values);
const hasNotChangedInput = nextInputType === inputType;
const hasNotChangedValue = nextMessage === message;
if (hasNotChangedValue && hasNotChangedInput) return;
if (nextInputType === PHONE_STEP_INPUT_MESSAGE) {
this.handleMessageInputType(nextMessage, nextInputType);
} else if (nextInputType === PHONE_STEP_INPUT_PHONE) {
this.handleMobileInputType(nextMessage, nextInputType);
} else if (nextInputType === PHONE_STEP_INPUT_HYBRID) {
this.handleHybridInputType(nextMessage, nextInputType);
}
}
Как лучше избавиться от дублирования componentWillReceiveProps в данном случае?