I'm using NativeBase's Toast component to show a message after successfully submitting a form, but I get this error message in the console every time I run it.
_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)
Here's the JSX in my render function:
<Container>
<Navbar title="Add an Inventory Item" backArrow />
<Content keyboardShouldPersistTaps="handled">
<InventoryItemAddForm
onSubmit={this._onSubmit}
data={formData}
enableReinitialize={true}
initialValues={initialValues}
/>
</Content>
<FooterTabs />
</Container>
And my _onSubmit
function:
_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()
})
}
I found out the root component of the app needs to be wrapped in nativebase's <Root>
component in order for Toast notifications to work reliably.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With