Meteor React, неперехваченная ошибка типа: не удается преобразовать undefined или null в object

#meteor-react

#meteor-react

Вопрос:

код на стороне сервера

 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
  

Не удалось найти причину этой ошибки. Я прошел через множество подобных ошибок при переполнении стека, но не смог найти никакого решения этой проблемы. Любая помощь будет оценена.

Ответ №1:

Убедитесь, что вы возвращаете объект из ‘createContainer’ как минимум:

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