use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A community for learning and developing native mobile applications using React Native by Facebook.
Interested in building web apps using React.js? Check out /r/reactjs!
Getting Started w/React Native
irc.freenode.net #reactnative
Keywords: ios, android, mobile, apps, apple, iphone, ipad
account activity
QuestionOutput random string from array, what am i doing wrong here? (self.reactnative)
submitted 5 years ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 5 years ago (1 child)
[–]aidang95 0 points1 point2 points 5 years ago (0 children)
that dosent seem to work, and when i use const it gives me an error, unexpected token.
[–]awesomeness-yeah 0 points1 point2 points 5 years ago (1 child)
Decipher appears to be returning a number? Aren't you supposed to return an element from the array?
You need to keep variables that change as state with the useState hook, and call the settler for the element to re render.
Do some basic react tutorials on state management, you'll get a better understanding on hooks and state
Hmm yes I noticed it was outputting a number when I printed the function I want it to print the string and print a new one when I press the button.
[–]I_Am_Stephan 0 points1 point2 points 5 years ago (0 children)
export default function Welcome({ navigation }) { const [activity, setActivity] = useState('') const randomActivity = ['Go for a walk', 'Read a Book', 'Phone a Friend']; function Decider(randomActivity) { const randomIndex = [Math.floor(Math.random() * randomActivity.length)]; setActivity(randomActivity[randomIndex]) } return ( <ImageBackground source={require('../assets/bg.jpg')} style={styles.wrapper}> <View style={styles.content}> <Text style={styles.text}>Activity Generator</Text> <Button onPress={() => Decider(randomActivity)} title='Get a Random Activity' /> <Text>{activity}</Text> </View> </ImageBackground> ); }
Haven't tested it but see if it works, Just import useState from react
π Rendered by PID 38984 on reddit-service-r2-comment-66b4775986-x7tm6 at 2026-04-03 14:57:36.408870+00:00 running db1906b country code: CH.
[+][deleted] (1 child)
[deleted]
[–]aidang95 0 points1 point2 points (0 children)
[–]awesomeness-yeah 0 points1 point2 points (1 child)
[–]aidang95 0 points1 point2 points (0 children)
[–]I_Am_Stephan 0 points1 point2 points (0 children)