React components to render two kinds of form elements I have two React components. The only difference is the input tag vs select tag. I'm trying to move the bulk of the duplicate code to a higher order component but I can't wrap my head around it. Any suggestions?

import React from "react";
import Style from "./style.scss";

export class FloatingLabelInput extends React.Component {
    render() {
        const { label, ...props } = this.props;
        const clsOK = props.value ? Style.ok : "";
        return (
            &lt;div className={`${Style.wrapper}`}&gt;
                &lt;input className={`${Style.input} ${clsOK}`} ref={el =&gt; this.input = el} {...props} /&gt;
                &lt;label className={`${Style.label}`} htmlFor={props.id}&gt;{label}&lt;/label&gt;
            &lt;/div&gt;
        );
    }
}

export class FloatingLabelDropDown extends React.Component {
    render() {
        const { label, ...props } = this.props;
        const clsOK = props.value ? Style.ok : "";
        return (
            &lt;div className={`${Style.wrapper}`}&gt;
                &lt;select
                    className={`${Style.input} ${clsOK}`}
                    ref={el =&gt; this.input = el} {...props} &gt;
                    {this.props.children}
                &lt;/select&gt;
                &lt;label className={`${Style.label}`} htmlFor={props.id}&gt;{label}&lt;/label&gt;
            &lt;/div&gt;
        );
    }
}
I think I have an understanding of what you are trying to do, but because select has children and and input does not it's a little tricky but this is what I came up with:

import React, { Component } from 'react'
import { render } from 'react-dom'

class FloatingLabel extends Component {
  render() {
    return (
      &lt;div&gt;
        &lt;this.props.render option='Hello'  /&gt;
      &lt;/div&gt;
    )
  }
}

class SelectDropDown extends Component {
  render() {
    return (
      &lt;select&gt;
        &lt;option&gt;{this.props.option}&lt;/option&gt;
      &lt;/select&gt;
    )
  }
}

class InputDropDown extends Component {
  render() {
    return (
      &lt;input /&gt;
    )
  }
}


render(&lt;FloatingLabel render={SelectDropDown} /&gt;, document.querySelector('#root'))


In this example you can create a &lt;FloatingLabel /&gt; component that can either take a SelectDropDown or a InputDropDown component as a prop. You can then render that prop in the FloatingLabel parent and pass whatever props that you need to pass down to the children.

Basically what you would be changing is the everything inside the div except for the label.