question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alert not working ('buttons.slice' is undefined)

See original GitHub issue

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

Steps To Reproduce

  1. Create alert function
export const createAlert = (title, msg) => {
    Alert.alert(
      title,
      msg,
      [
        { text: "OK", onPress: () => console.log("OK Pressed") }
      ],
      { cancelable: true }
    );
}
  1. Call function: 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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:10

github_iconTop GitHub Comments

60reactions
abdirisakmocommented, Feb 9, 2020

this is worked for me Alert.alert(‘Error’, ‘Please enter some text’, [ { text: “OK”, onPress: () => console.log(“OK Pressed”) } ], { cancelable: true });

4reactions
JohnFelixLimcommented, Apr 18, 2020

Maybe you forgot the second parameter.

Alert.alert( “title here”, “”, // empty string [ { text: “OK”, onPress: () => console.log(“OK Pressed”) } ], { cancelable: true } );

Read more comments on GitHub >

github_iconTop Results From Across the Web

React native buttons.slice is not a function - Stack Overflow
I'm trying to print a variable using Alert.alert it might be me but I'm not able ...
Read more >
How to Show Alert in React Native
Try uninstalling the cli and run the cli using npx. This will make a project structure with an index file named App. js...
Read more >
JavaScript undefined Property - W3Schools
The undefined property indicates that a variable has not been assigned a value, or not declared at all. ... undefined() is an ECMAScript1...
Read more >
Alert - Deque University
Note: The code below is functional only in the context of the complete JavaScript file. In the @alert section: function createAlert(message) { var...
Read more >
https://eddir.alsde.edu/EdDir/Scripts/bootstrap.mi...
parentNode)\n },\n\n jQueryDetection() {\n if (typeof $ === 'undefined') ... triggerChangeEvent = false\n }\n } else {\n // if it's not a radio...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found