我一直在試圖使用Tracker React顯示登錄用戶的用戶名。 我已經刪除了自動發佈軟件包。顯示Meteor.user()。使用跟蹤器的用戶名React
/Client/components/dashboard/sidebar.jsx
import React, {Component} from 'react'
import TrackerReact from 'meteor/ultimatejs:tracker-react';
export default class Sidebar extends TrackerReact(Component) {
constructor() {
super();
this.state = {
subscription: {
users: Meteor.subscribe('users')
}
};
}
render() {
return(
<div>
<h1>{Meteor.user().username}</h1>
</div>
);
}
/服務器/出版/ userPublications
Meteor.publish("users", function() {
return Meteor.users.find();
});
我得到一個空對象,而console.log(Meteor.user())
。但是,我可以使用Meteor DevTools查看當前的用戶名。
我錯過了什麼拼圖塊?
難道你不需要導入流星?像'meteor/meteor''的導入{Meteor}? – CodeChimp
我解決了這個問題[鏈接到類似問題](https://stackoverflow.com/questions/43417385/meteorjs-get-user-profile-on-client-side/43422269#43422269) – Daltron