Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useOpenLinkedThread.ts

16 lines667 Bytes

1import { StackActions, useNavigation } from "@react-navigation/native";
2import { useCallback } from "react";
3import { linkedThreadStep } from "../../lib/android-workspace-navigation";
4​
5export function useOpenLinkedThread() {
6 const navigation = useNavigation();
7 return useCallback(
8 (target: { readonly environmentId: string; readonly threadId: string }) => {
9 const state = navigation.getState();
10 const step = state ? linkedThreadStep(state, target) : "push";
11 if (step === "pop") navigation.dispatch(StackActions.pop());
12 else if (step === "push") navigation.dispatch(StackActions.push("Thread", target));
13 },
14 [navigation],
15 );