0

I'm trying to print My letters array on the screen and nothing is currently showing.

I've also tried to wrap the touchableOpacity view another View also or change it to View or Text only but I didn't succeeded yet.

const letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m'];

const OptionalLetters = props => {

    const mixedLetters = () => {

        letters.map(()=> (letter, key) => {
            return (
                <TouchableOpacity key={Math.random()} onPress={()=> console.log('letter pressed')}>
                    <Text>{letter}</Text>
                </TouchableOpacity>
            )
        })
    }

    return (
        <View style={styles.screen}>
            {mixedLetters()}
        </View>
    )
}
1
  • Text is a component ?. Please show the html of Text Commented May 5, 2020 at 17:38

3 Answers 3

1

You're not returning the map. Do this:

const letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m'];

const OptionalLetters = props => {

    const mixedLetters = () => {

        return letters.map((letter, key) => {
            return (
                <TouchableOpacity key={Math.random()} onPress={()=> console.log('letter pressed')}>
                    <Text>{letter}</Text>
                </TouchableOpacity>
            )
        })
    }

    return (
        <View style={styles.screen}>
            {mixedLetters()}
        </View>
    )
}
Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you forgot a return statement here letters.map

Comments

0

You have an extra () => in your code.

Change

letters.map(()=> (letter, key) => {

To

letters.map((letter, key) => {

You can also use the key (which holds the index so it's always unique) as the key

1 Comment

Haha yeah, that too!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.