I'm trying to create my own smart pop-up component that can open some components inside myself, but my implementation is not very good because it does not work.
I use the reduction method to create pop-ups, and the action of opening my pop-up allows me to get the name of any component to render before the pop-up opens;
But I have a problem, after receiving the parameter, in our case it is nameOfComponent , I need to select and display a component named nameOfComponent .
And now my question is, how can it display a component from an array?
// He my components import Login from '../Login/login.js'; import Logout from '../Logout/logout.js'; const popupContent = { Login : Login, logout: Logout }; // My component class Popup extends Component { componentDidUpdate () { // for example const nameOfComponent = "Login"; this.body = this.setBodyPopup(nameOfComponent); return true; } setBodyPopup(property){ return popupContent[property]; } render() { // I want to render some element from popupContent here <div> // <this.body /> // it jsx format {this.body} </div> } }
source share