I have data called hello.
If I have hello[0] data, I want to run hello.map and list the buttons. However, the Pressable component is vertically aligned, but I want to do it horizontally.
So, I am trying to change the direction by giving a View on top of the map function. If i put a View, an Unexpected Token error occurs.
How do I fix my code?
JavaScript
x
25
25
1
hello = [
2
{ originName: "growthLength 1"},
3
{ originName: "growthLength 2"},
4
]
5
6
7
8
{
9
hello[0] ? (
10
<View style={{flexDirection:'row'}}> // << here
11
12
hello.map((v) => {
13
return(
14
<>
15
<Pressable>
16
<Image />
17
</Pressable>
18
</>
19
)
20
})
21
22
</View>
23
) : (null)
24
}
25
Advertisement
Answer
Change your code like this
JavaScript
1
14
14
1
{hello[0] ? (
2
<View style={{ flexDirection: 'row' }}>
3
{hello.map((v) => {
4
return (
5
<>
6
<Pressable>
7
<Image />
8
</Pressable>
9
</>
10
);
11
})}
12
</View>
13
) : null}
14