reactjs – How can i render another file in react native without onPress event
To render a file in React Native without an onPress event, you can simply set the state of the showWebView variable to false. This will cause the code within the else block to be executed, which should contain the code to render your file.
Sample Code Snippet:
const MyComponent = () => {
const [showWebView, setShowWebView] = useState(true);
return (
<View>
{showWebView ? (
// code within if condition
<Text>Click the button to render the file</Text>
) : (
// code within else condition
<Text>This is where the file will be rendered</Text>
)}
<Button
title="Render file"
onPress={() => setShowWebView(false)}
/>
</View>
);
};
In the above sample code snippet, the initial state of showWebView is set to true so the code within the if block will be executed (which will display a message asking the user to click the button to render the file.)
When the user clicks the button, the onPress event sets the showWebView state to false (which causes the code within the else block to be executed, rendering the file in the component.)
You can replace the <Text> component in the else block with the code to render your file.
Read more here: Source link
