2017-04-18 47 views
1

我使用NativeBase的Toast組件在成功提交表單後顯示消息,但每次運行它時都會在控制檯中收到此錯誤消息。當使用NativeBase Toast組件時,無法讀取React Native中的null屬性'_root'

_onSubmit error TypeError: Cannot read property '_root' of null 
    at Function.show (ToastContainer.js:79) 
    at InventoryItemAdd.js:40 
    at tryCallOne (core.js:37) 
    at core.js:123 
    at JSTimers.js:98 
    at Object.callTimer (JSTimersExecution.js:95) 
    at Object.callImmediatesPass (JSTimersExecution.js:199) 
    at Object.callImmediates (JSTimersExecution.js:214) 
    at MessageQueue.js:222 
    at guard (MessageQueue.js:46) 

這裏的JSX在我的渲染功能:

<Container> 
    <Navbar title="Add an Inventory Item" backArrow /> 
    <Content keyboardShouldPersistTaps="handled"> 
     <InventoryItemAddForm 
      onSubmit={this._onSubmit} 
      data={formData} 
      enableReinitialize={true} 
      initialValues={initialValues} 
     /> 
    </Content> 
    <FooterTabs /> 
</Container> 

而且我_onSubmit功能:

_onSubmit = ({name, inventoryTypeId, internalCode, description = "", measurementUnitId}) => { 
    const {inventoryItemCreate, showErrors} = this.props 

    return inventoryItemCreate({ 
     input: { 
      name: name.trim(), 
      inventoryTypeId, 
      internalCode: internalCode.trim(), 
      description: description.trim(), 
      measurementUnitId, 
     } 
    }) 
     .then(({data: {inventoryItemCreate}}) => { 
      dismissKeyboard() 
      Toast.show({ 
       text: "Inventory item added successfully!", 
       position: "bottom", 
       buttonText: "Okay", 
       type: "success", 
       duration: 2000, 
      }) 
      Actions.InventoryItemDetails({id: inventoryItemCreate.id}) 
     }) 
     .catch((error) => { 
      console.log('_onSubmit error', error) 
      showErrors() 
     }) 
} 
+0

您是否找到了解決方案?我有同樣的問題。 –

+0

我還沒有找到能夠完全解決這個問題的解決方案,但我認爲這可能與多個動畫同時運行有關。我設法通過先導航場景然後在另一個'then'函數中顯示敬酒來解決這些代碼領域中的一些問題,但我仍然不清楚它爲什麼不起作用或者爲什麼有時會修復它。 –

+0

我看到了謝謝。該組件可能仍然是自行竊聽。 –

回答

相關問題