Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
React Native navigationOptions stateless component
// 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