Skip to content

Instantly share code, notes, and snippets.

@marlosirapuan
Created May 8, 2019 15:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marlosirapuan/5ddac990747e3dc77c785e36ecfb8830 to your computer and use it in GitHub Desktop.
Save marlosirapuan/5ddac990747e3dc77c785e36ecfb8830 to your computer and use it in GitHub Desktop.
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