Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
app-stream-context-blog
import React, { useEffect } from "react";
import { View, Text } from "react-native";
import branch from "react-native-branch";
import BranchProvider, { BranchConsumer } from "./BranchContext";
let App = ({ setContextData }) => {
// run code in useEffect callback on App load
useEffect(() => {
// branch's subscribe method listens for deeplink activity
branch.subscribe(({ error, params }) => {
if (error) return;
// if the App loads via deeplink, save deeplink params in context
setContextData(params);
});
}, []);
return (
<View>
<Text>Save Deeplink Content on App Load!</Text>
</View>
);
};
App = props => (
// provide value stored in context to child components
<BranchProvider>
{/* destructure context value(s) and pass as props into App */}
<BranchConsumer>
{({ setContextData }) => (
<App {...props} setContextData={setContextData} />
)}
</BranchConsumer>
</BranchProvider>
);
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.