I have a component that has some other components imported in for example:
import ComponentA from './components/ComponentA.js';
import ComponentB from './components/ComponentB.js';
import ComponentC from './components/ComponentC.js';
class Main extends Component {
...
then I have a function inside the main component named returnChild(String childName) that gets a string input, for example ComponentA or ComponentB, and returns the Component Object.
now I'm using a switch case to do it but components are too many and my source is messy. is there any way to get the value by string name in reactJS? For example:
returnChild = (childName) => {
return get_value_by_name(childName)
}
Maincode.