As commented,
In a component based architecture, you will have a HOC which will call your custom component and that will internally call some generic component. So with respect to your custom component, HOC is a parent component which will supply props. Your component will maintain its state, and based on provided props and computed state, you will pass props to this generic component, which is a child component.
TL;DR
Example:
Requirement:
You are trying to create a form that will accept 2 numbers and display their total.
What you need:
- A form component that will create 2 input fields.
- A input component that will accept value and return it to the caller.
- A validator that will check if the value entered is a number or not.
- A label to display total.
- An event to process inputs.
Implementation:
You start in a ground-up fashion with input components. You cannot use <input type='text'
as it will not have your custom validator. You cannot use <input type='number'
as it adds spinner. So you create a custom component which uses type="text"
and write your own validator
Now for this component, its value cannot be the value entered by user as it can be NaN. So you need a variable to store the processed value. You also need this value to be created once and not every time to persist its value. This place is called state.
Now that you have an input component, you need to stitch it together. So you create a form with your custom components and uses handlers/functions for communication. These functions passed to components are called as props.
So, to summarize, state is something you as a component will hold and prop is what you get from external environment (say some component).
Now, in this component tree, who do you call parent/child component? It is always referred based on a context. So in above example, w.r.t CustomInput
component, since FormComponent
is calling it, that is its parent. Similarly, any component it is calling will be its child component.