1
I want to create components with Textinput, the default being my mask-free Input component, and the kids will have a mask or some other treatment.
I currently have the default input that contains only the styles and returns the raw text when typing. I also have an Input with CPF/ CNPJ mask, and at the time of exporting I am using an index.js file that only contains these two components and exports them.
index js.
import Input from './Input'
import CpfCnpj from './input-masks/InputCpfCnpj'
export { CpfCnpj }
export default Input
But I would like to use this way when you want to wear without masks:
<Input {...this.props} />
And so when you need some mask:
<Input.CpfCnpj {...this.props} />
One way I found it was to do it in the archive index js.
import Input from './Input'
import CpfCnpj from './input-masks/InputCpfCnpj'
Input.CpfCnpj = CpfCnpj
export default Input
I wonder if there is another way, and if that is good practice?
Inheritance between components is not recommended. Composition would be a better solution for this, see: https://reactjs.org/docs/composition-vs-inheritance.html
– Tulio Faria