Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show multiple components in reactjs

I have written a simple application using react native for android. i want to know how do i use more than one component adjacent to each other in the return function. If I put a toolbar tag, it gives an error.

return (
<MovieScreen
      style={{flex: 1}}
      navigator={navigationOperations}
      movie={route.movie}
/>
);

Above works. Below one gives error

return (
<Toolbar/>
<MovieScreen
      style={{flex: 1}}
      navigator={navigationOperations}
      movie={route.movie}
/>
);

Please help.

like image 393
Paul Richie Avatar asked Mar 13 '23 12:03

Paul Richie


2 Answers

Enclose it in a View tag if you think that's how you want to showcase it.

return (
  <View style={{flex: 1}}>
    <Toolbar />
    <MovieScreen
      style={{flex: 1}}
      navigator={navigationOperations}
      movie={route.movie}
    />
  </View>
);

This should work.

like image 152
Sharan Kashyap Avatar answered Mar 16 '23 02:03

Sharan Kashyap


You cannot return 2 values remember? You can only return one encapsulated tag. So, wrap a view. It will work :)

return (
  <View style={{flex: 1}}>
    <Toolbar />
    <MovieScreen
      style={{flex: 1}}
      navigator={navigationOperations}
      movie={route.movie}
    />
  </View>
);
like image 36
Niharika Neeraj Avatar answered Mar 16 '23 00:03

Niharika Neeraj