The Alert function no longer works in my project. I'm attempting to create an alert when the user encounters an error, but instead a JS error is thrown.
TypeError: buttons.slice is not a function. (In 'buttons.slice(0, 3)', 'buttons.slice' is undefined)
at alert(/Users/craig/Dev/oddBox/node_modules/react-native/Libraries/Alert/Alert.js:69:24)
at tryCatch(/Users/craig/Dev/oddBox/node_modules/regenerator-runtime/runtime.js:45:44)
at invoke(/Users/craig/Dev/oddBox/node_modules/regenerator-runtime/runtime.js:271:30)
at tryCatch(/Users/craig/Dev/oddBox/node_modules/regenerator-runtime/runtime.js:45:44)
at invoke(/Users/craig/Dev/oddBox/node_modules/regenerator-runtime/runtime.js:135:28)
at Promise.resolve.then$argument_1(/Users/craig/Dev/oddBox/node_modules/regenerator-runtime/runtime.js:147:19)
at tryCallOne(/Users/craig/Dev/oddBox/node_modules/promise/setimmediate/core.js:37:14)
at setImmediate$argument_0(/Users/craig/Dev/oddBox/node_modules/promise/setimmediate/core.js:123:25)
at _callTimer(/Users/craig/Dev/oddBox/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14)
at _callImmediatesPass(/Users/craig/Dev/oddBox/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17)
at callImmediates(/Users/craig/Dev/oddBox/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30)
at callImmediates([native code])
at flushedQueue([native code])
at invokeCallbackAndReturnFlushedQueue([native code])
React Native version:
System:
OS: macOS Mojave 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Memory: 157.77 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.13.1 - /usr/local/bin/node
Yarn: 1.21.1 - ~/.yarn/bin/yarn
npm: 6.12.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 25, 26, 28
Build Tools: 23.0.1, 25.0.0, 26.0.1, 26.0.2, 26.0.3, 28.0.3
System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: ~16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz => 0.61.4
npmGlobalPackages:
react-native-cli: 2.0.1
react-native: 0.59.4
export const createAlert = (title, msg) => {
Alert.alert(
title,
msg,
[
{ text: "OK", onPress: () => console.log("OK Pressed") }
],
{ cancelable: true }
);
}
createAlert("Error", "I am an error")Describe what you expected to happen:
Expect the alert to show on the device, but instead the exception is caught by Sentry.
I have this same issue.
@Craigson After Googling around (I had the same issue), this code snippet I found works
Alert.alert(
//title
'Hello',
//body
'I am two option alert. Do you want to cancel me ?',
[
{text: 'Yes', onPress: () => console.log('Yes Pressed')},
{text: 'No', onPress: () => console.log('No Pressed'), style: 'cancel'},
],
{ cancelable: false }
//clicking out side of alert will not cancel
);
this is worked for me
Alert.alert('Error', 'Please enter some text', [
{ text: "OK", onPress: () => console.log("OK Pressed") }
],
{ cancelable: true });
@abdirisaak thank you! this worked for me.
Maybe you forgot the second parameter.
Alert.alert(
"title here",
"", // empty string
[
{ text: "OK", onPress: () => console.log("OK Pressed") }
],
{ cancelable: true }
);
@abdirisakmo thank you, your solution worked.
This worked for me.
Alert.alert("Error", "Enter an item", [{ text: "OK" }]);
Almost the same issue. Sentry error : TypeError callImmediates([native code]) error u.slice is not a function. (In 'u.slice(0,3)', 'u.slice' is undefined). In project didn't find the "u.slice" expression
expo diagonistics:
Expo CLI 3.27.4 environment info:
System:
OS: Windows 10 10.0.18362
Binaries:
Node: 12.18.2 - xxxxxxxnodejsnode.EXE
npm: 6.14.8 - xxxxxxRoamingnpmnpm.CMD
npmPackages:
expo: ^38.0.9 => 38.0.10
react: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
react-navigation: ^4.4.0 => 4.4.0
Expo Workflow: managed
@abdirisaak your solution worked, thanks man
Most helpful comment
this is worked for me
Alert.alert('Error', 'Please enter some text', [
{ text: "OK", onPress: () => console.log("OK Pressed") }
],
{ cancelable: true });