Created
May 8, 2019 15:16
-
-
Save marlosirapuan/5ddac990747e3dc77c785e36ecfb8830 to your computer and use it in GitHub Desktop.
React Native navigationOptions stateless component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app.js | |
const onPressOpenLink = async (url, title) => { | |
const { navigate } = props.navigation | |
navigate('Web', { url: url, title: title }) | |
} | |
// webview.js | |
import React, { useState, useEffect } from 'react' | |
import { WebView } from 'react-native-webview' | |
const Web = (props) => { | |
const [url, setUrl] = useState('') | |
useEffect(() => { | |
function handleURL () { | |
const { navigation } = props | |
setUrl(navigation.getParam('url')) | |
} | |
handleURL() | |
}, []) | |
return ( | |
<WebView originWhitelist={['*']} useWebKit source={{ uri: url }} /> | |
) | |
} | |
Web.navigationOptions = (props) => ( | |
{ | |
title: props.navigation.getParam('title') | |
} | |
) | |
export default Web |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment