Meteor React, Uncaught TypeError: Cannot convert undefined or null to object

Meteor React, Uncaught TypeError: Cannot convert undefined or null to object

服务器端代码

Meteor.methods({
'users.profileUpdate'(profileData){

    isValid = ProfileSchema.namedContext("myContext").validate(profileData);

    if(! this.userId){
        throw new Meteor.Error('not-authorized');
    }

    if(isValid){
        Meteor.users.update({_id:this.userId}, { 
            $set: { 
                profile: profileData 
            } 
        });
    }

},


})

客户端代码

export default class Profile extends Component{

constructor() {
    super();
    this.state = {
      subscription: {
        users: Meteor.subscribe('users')
      }
    }
}

componentWillUnmount() {
    this.state.subscription.users.stop();
  }

render(){
    return(
        <div className="row">
            <div className="container">
                {this.props.user ?
                    <header>
                        <div>
                            <h3>User Profile</h3>
                        </div>
                        <div className="profilePic">
                            <img src={"/images/"+this.props.user._id+'.png'} alt="user" />  
                        </div>

                        <h1>Username: {this.props.user.username}</h1>

                        <h2>Email Id: {this.props.user.address}</h2>

                        {this.props.user.profile ?
                            <div className="profileInfo">
                                <h3>First Name: {this.props.user.profile.first_Name}</h3>                               
                                <h3>Last Name: {this.props.user.profile.last_Name}</h3>                             
                                <h3>Phone No: {this.props.user.profile.phonNo}</h3>                                                 
                                <h3>City: {this.props.user.profile.city}</h3>                                                                       
                                <h3>Country: {this.props.user.profile.country}</h3>
                            </div>  
                        :
                            <div className="profileInfo">
                                <h3>First Name: </h3>                               
                                <h3>Last Name: </h3>                                
                                <h3>Phone No: </h3>                                                 
                                <h3>City: </h3>                                                                     
                                <h3>Country: </h3>
                            </div>      
                        }

                    </header>
                :
                    ''
                }       
            </div>                                      
        </div>
    )
}
}

export default createContainer(() => {

if(Meteor.users.findOne({username:FlowRouter.getParam("profileName")}) != undefined){
    return {
        user: Meteor.users.findOne({username:FlowRouter.getParam("profileName")}),
        currentUser: Meteor.user()
    }
}

}, Profile);

通过页面上的链接导航时一切正常,但每当重新加载个人资料页面时都会弹出此错误。

Uncaught TypeError: Cannot convert undefined or null to objectkeys @ es5-shim.js:1103calculateData @             ReactMeteorData.jsx:111componentWillMount @    ReactMeteorData.jsx:5(anonymous function) @ ReactCompositeComponent.js:347measureLifeCyclePerf @ ReactCompositeComponent.js:74performInitialMount @ ReactCompositeComponent.js:346mountComponent @ ReactCompositeComponent.js:257mountComponent @ ReactReconciler.js:47mountChildren @ ReactMultiChild.js:240_createInitialChildren @ ReactDOMComponent.js:699mountComponent @ ReactDOMComponent.js:524mountComponent @ ReactReconciler.js:47mountChildren @ ReactMultiChild.js:240_createInitialChildren @ ReactDOMComponent.js:699mountComponent @ ReactDOMComponent.js:524mountComponent @ ReactReconciler.js:47performInitialMount @ ReactCompositeComponent.js:370mountComponent @ ReactCompositeComponent.js:257mountComponent @ ReactReconciler.js:47performInitialMount @ ReactCompositeComponent.js:370mountComponent @ ReactCompositeComponent.js:257mountComponent @ ReactReconciler.js:47mountComponentIntoNode @ ReactMount.js:105perform @ Transaction.js:138batchedMountComponentIntoNode @ ReactMount.js:127perform @ Transaction.js:138batchedUpdates @ ReactDefaultBatchingStrategy.js:63batchedUpdates @ ReactUpdates.js:98_renderNewRootComponent @ ReactMount.js:321_renderSubtreeIntoContainer @ ReactMount.js:402render @ ReactMount.js:423(anonymous function) @ client.js:62

debug.js:41 Exception from Tracker recompute function:
debug.js:41 TypeError: Cannot read property '_currentElement' of null
at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js:742)
at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js:721)
at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js:642)
at ReactCompositeComponentWrapper.performUpdateIfNecessary (ReactCompositeComponent.js:558)
at Object.performUpdateIfNecessary (ReactReconciler.js:158)
at runBatchedUpdates (ReactUpdates.js:151)
at ReactReconcileTransaction.perform (Transaction.js:138)
at ReactUpdatesFlushTransaction.perform (Transaction.js:138)
at ReactUpdatesFlushTransaction.perform (ReactUpdates.js:90)
at Object.flushBatchedUpdates (ReactUpdates.js:173)

debug.js:41 Exception from Tracker recompute function:
debug.js:41 TypeError: Cannot read property '_currentElement' of null
at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js:742)
at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js:721)
at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js:642)
at ReactCompositeComponentWrapper.performUpdateIfNecessary (ReactCompositeComponent.js:558)
at Object.performUpdateIfNecessary (ReactReconciler.js:158)
at runBatchedUpdates (ReactUpdates.js:151)
at ReactReconcileTransaction.perform (Transaction.js:138)
at ReactUpdatesFlushTransaction.perform (Transaction.js:138)
at ReactUpdatesFlushTransaction.perform (ReactUpdates.js:90)
at Object.flushBatchedUpdates (ReactUpdates.js:173)
148ReactDOMComponentTree.js:107 Uncaught TypeError: Cannot read property '__reactInternalInstance$e1l06bgkqvy3bohv5g41v2t9' of null

无法找到导致此错误的原因。我在堆栈溢出时遇到了许多类似的错误,但无法找到有关此问题的任何解决方案。任何帮助,将不胜感激。

确保至少从 'createContainer' 返回一个对象:

export default TestContainer = createContainer(({ params }) => {return {}}, Test);
export default TestContainer = createContainer(({ params }) => new Object, Test);