yarin Cohen
yarin Cohen

Reputation: 1142

React native buttons.slice is not a function

I'm trying to print a variable using Alert.alert it might be me but I'm not able to do it Here's my code

const [reg, setRegion] = useState('');
      Alert.alert(
      "Confirm",
      "this is just a "  + {reg},  
      [
        {
          text: "Cancel",
          onPress: () => console.log("Cancel Pressed"),
          style: "cancel"
        },
        { text: "OK", onPress: () => console.log("OK Pressed") }
      ],
      { cancelable: false }
    );
    }

How can I print {reg} variable with a string?

Upvotes: 5

Views: 4447

Answers (2)

Sourabh Chavan
Sourabh Chavan

Reputation: 187

If you getting this while using Alert in React native below solution worked for me.

Alert.alert("Error", "Enter an item", [{ text: "OK" }]);

Upvotes: 8

Konstantin Yarish
Konstantin Yarish

Reputation: 196

const [reg, setRegion] = useState('');
  Alert.alert(
  "Confirm",
  `this is just a ${reg}`,  
  [
    {
      text: "Cancel",
      onPress: () => console.log("Cancel Pressed"),
      style: "cancel"
    },
    { text: "OK", onPress: () => console.log("OK Pressed") }
  ],
  { cancelable: false }
);
}

Upvotes: 6

Related Questions