I have a couple of Views that render an entire page and I want to switch between them. I could use a screen for each view and navigate between screens but that would be a bit bad UX to show a transition everytime. See it like some tabs at the top of the page that each render different content.
I've been doing it with conditionals like below. Is there another way to do this more efficiently?
import React, { useState, useEffect } from 'react';
import {StyleSheet, View, Image, Text, Dimensions, ImageBackground, Button} from 'react-native';
const RM = ( {route, navigation } : any) => {
const [view, setView] = useState("A");
return (
<>
<View>
<Button onPress={() => setView("A")} title="Set A" />
<Button onPress={() => setView("B")} title="Set B" />
<Button onPress={() => setView("C")} title="Set C" />
</View>
<View>
{view === "A" && (
<ComponentA />
)}
{view === "B" && (
<ComponentB />
)}
{view === "C" && (
<ComponentC />
)}
</View>
</>
);
};
export default RM;