2016-12-30 147 views
0

在這裏使用與流星反應,我有主要組件稱爲應用程序,它包裝頁面佈局(標題,側邊欄,右側欄)。流星+反應+ createcontainer

export default class App extends Component { 
    render() { 
    return (
     <div> 
     <nav className="navigation"> 
      <Header /> 
      <Sidebar /> 
     </nav> 
     <div className="content"> 
      <Subnavbar /> 
      <div className="container"> 
      {this.props.children} 
      </div> 
     </div> 
     <Rightsidebar /> 
     </div> 
    ); 
    } 
}; 

我正在嘗試使用Meteor的內置身份驗證系統來設置身份驗證系統。使用「accounts-password」包。

在我的知識庫中,我需要使用'meteor/react-meteor-data'中的createContainer將auth參數注入組件。

這個例子類似:

import { createContainer } from 'meteor/react-meteor-data'; 
import MainPage from '../pages/MainPage.jsx' 
export default MainContainer = createContainer(({params}) => { 
    const currentUser = Meteor.user(); 
    return { 
    currentUser, 
    }; 
}, MainPage); 

然而,在上述例子中,只有注入了PARMS單個組件,我怎麼能去我的應用程序(頭,側邊欄注射身份驗證信息到所有組件..等)

您的幫助是高度讚賞。

謝謝

回答

1

如果您在createContainer包裹App,然後App將有一個道具currentUser。然後由App負責將currentUser prop傳遞給您的所有組件。如果您發現自己在currentUser附近傳遞的太多,則只能將需要currentUser的組件包裝在createContainer中。

在這種情況下,您將有HeaderContainerSidebarContainer等,每個包裹createContainer

+0

我最終創建了'HeaderContainer'根據您的答案,它的工作原理,感謝您的幫助:) – Deano