我嘗試使我的「智能」彈出組件,它可以打開自己內部一些組件,但我的實現並不好,因爲它不工作。我如何渲染沒有jsx格式的反應組件?
我使用redux方法創建彈出窗口和打開彈出窗口的動作,可以在彈出窗口打開之前獲取任何打開的組件的名稱;
但我有一些問題,得到的參數後,在我們的情況下,它nameOfComponent,我需要選擇與名nameOfComponent渲染組件。
現在我的問題,它如何從數組呈現組件?
// He's 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's jsx format
{this.body}
</div>
}
}
我不知道爲什麼你使用'componentDidUpdate',我認爲你可以在這種情況下使用構造 - https://jsfiddle.net/69z2wepo/36027/ –
因爲我的彈出可以在打開另一個內容,通過道具傳遞。我有一個彈出式spa。 –