【发布时间】:2017-04-25 03:29:48
【问题描述】:
我目前正在使用themeteorchef/base 样板项目。当我从 Meteor/Blaze 转到 Meteor/React 世界时,这真的很有帮助。
通过容器将订阅数据传递给组件非常简单。但是,尝试创建一个基本的个人资料页面非常困难,我觉得我错过了一些简单的东西。到目前为止,我已经设法将用户对象作为 json 字符串传递(这并不理想)。
我的问题是 - 将登录用户的信息传递给反应组件的最佳方式是什么?
在我的容器中,我有...
import { Meteor } from 'meteor/meteor';
import { composeWithTracker } from 'react-komposer';
import ViewProfile from '../pages/ViewProfile.js';
import Loading from '../components/Loading.js';
const composer = ({ params }, onData) => {
const currentUser = JSON.stringify( Meteor.user() );
onData(null, { currentUser });
};
export default composeWithTracker(composer, Loading)(ViewProfile);
而我的组件是一个简单的显示...
import React from 'react';
import NotFound from './NotFound';
const ViewProfile = ( { currentUser } ) => {
return currentUser ? (
<p>{ currentUser }</p>
) : <NotFound />;
};
ViewProfile.propTypes = {
currentUser: React.PropTypes.string
};
export default ViewProfile;
【问题讨论】:
标签: javascript reactjs meteor