Reactjs 未为deepLink调用useEffect内的函数

Reactjs 未为deepLink调用useEffect内的函数,reactjs,react-native,redux,react-redux,deep-linking,Reactjs,React Native,Redux,React Redux,Deep Linking,下午好,我正在尝试使用react router flux为react native设置deepLinking,但我的useEffect中的函数似乎没有运行。我相信这可能是因为它没有得到正确的状态。当我访问flow_id的URL时,它只在UI中呈现我在URL中放置的内容,但函数不运行。它应该将流id与场景关键点匹配,并使用适当的流和子流打开场景。任何指导都将不胜感激 import React, { useEffect } from 'react'; import { Linking, View,

下午好,我正在尝试使用react router flux为react native设置deepLinking,但我的useEffect中的函数似乎没有运行。我相信这可能是因为它没有得到正确的状态。当我访问flow_id的URL时,它只在UI中呈现我在URL中放置的内容,但函数不运行。它应该将流id与场景关键点匹配,并使用适当的流和子流打开场景。任何指导都将不胜感激

import React, { useEffect } from 'react';
import { Linking, View, Text } from 'react-native';
import { Actions } from 'react-native-router-flux';
import { useSelector, useDispatch } from 'react-redux';
import Router from '../Router';
import reducers from '../reducers';
import * as ActionCreators from '../actions';
import * as Globals from '../library/utils/globals';
import {
  selectFlow,
  flowsFetch,
  subFlowsFetch,
} from '../actions';

const DeepLink = (props) => {
  useEffect(() => {
    const onDeepLink = (url) => {
      const dispatch = useDispatch();
      const allFlows = useSelector(
        (state) => state.flows.all
      );
      console.log(props.flow_id);
      console.log('[DeepLink] onDeepLink: ', url);
      const flow = allFlows.filter((obj) => {
        return obj.key === url.key;
      });
      dispatch(flowsFetch());

      if (
        allFlows.getState().app_bootstrap.completed === true
      ) {
        console.log('[DeepLink] bootstrap completed!');

        Actions.reset('mainTabs');

        if (url.hasOwnProperty('scene_key')) {
          console.log('[DeepLink] scene_key exists');
          console.log(
            '[DeepLink] flow key: ',
            url.flow_key
          );

          // Check if Deepline is a defined flow
          if (
            (props.flow_id === url.scene_key) ===
              'flowDescription' &&
            url.flow_key !== undefined
          ) {
            console.log('[DeepLink] scene_key is a flow!');
            console.log(
              '[DeepLink] # of flows with matching key in store: ',
              flow.length
            );

            // If no flows of matching key found, wait for database fetch
            if (flow.length == 0) {
              console.log(
                '[DeepLink] flow not found locally; starting timer...'
              );
              dispatch(flowsFetch());
              Actions.reset('notificationLoader', {
                parameters: url,
              });

              // Timer to wait for update to flows
              setTimeout(() => {
                // Check for flows in updated store
                const updatedAllFlows = allFlows.getState()
                  .flows.all;
                const updatedFlow = updatedAllFlows.filter(
                  (obj, index) => {
                    return obj.key === url.flow_key;
                  }
                );

                // If flow still not found, go home
                if (updatedFlow.length == 0) {
                  console.log(
                    '[DeepLink] desired flow still not found; returning to home screen'
                  );
                  Actions.reset('mainTabs');
                } else {
                  console.log(
                    '[DeepLink] timer ended -- flow successfully fetched!'
                  );
                }
              }, 5000);
            } else {
              console.log('[DeepLink] flow found locally!');

              // Go to selected flow
              dispatch(selectFlow(flow[0]));
              dispatch(
                subFlowsFetch(
                  flow[0].flow_key,
                  (sub_flows) => {
                    Actions.flowDescription({
                      flowCategory: flow[0].flow_categories,
                      title: flow[0].label,
                      duration: url.duration,
                      imageUri: flow[0].image_uri,
                      lock: url.lock,
                      dynamicPacingSupport:
                        url.dynamic_pacing_support,
                      choiceSupport: url.choice_support,
                      sub_flows,
                      flow: flow[0],
                    });
                  }
                )
              );
            }

            // Check if DeepLink is an undefined flow
          } else if (
            url.scene_key === 'flowDescription' &&
            url.flow_key === undefined
          ) {
            console.log(
              '[DeepLink] Error: flow key is undefined'
            );

            // DeepLink is not a flow
          } else {
            console.log(
              '[DeepLink] scene_key is NOT a flow: ',
              url.scene_key
            );

            // Try to go to screen specified by scene_key
            try {
              Actions[url.scene_key]();
            } catch (err) {
              console.log(
                '[DeepLink] Error: invalid scene_key'
              );
            }
          }
        } else {
          console.log(
            '[DeepLink] scene_key does not exist'
          );
        }
      } else {
        console.log('[DeepLink] bootstrap not completed!');

        if (
          url.hasOwnProperty('scene_key') &&
          url.scene_key !== 'flowDescription'
        ) {
          setTimeout(() => {
            if (
              allFlows.getState().app_bootstrap
                .completed === true
            ) {
              console.log(
                '[DeepLink] bootstrap completed for screen: ',
                url.scene_key
              );
              try {
                Actions[url.scene_key]();
              } catch (err) {
                console.log(
                  '[DeepLink] Error: invalid scene_key'
                );
              }
            }
          }, 2000);
        } else if (
          url.hasOwnProperty('scene_key') &&
          (props.flow_id === url.scene_key) ===
            'flowDescription'
        ) {
          setTimeout(() => {
            if (
              allFlows.getState().app_bootstrap
                .completed === true
            ) {
              // Check for flows in updated store
              const bootstrap_updatedAllFlows = allFlows.getState()
                .flows.all;
              const bootstrap_updatedFlow = bootstrap_updatedAllFlows.filter(
                (obj, index) => {
                  return obj.key === url.flow_key;
                }
              );

              // If flow still not found, go home
              if (bootstrap_updatedFlow.length == 0) {
                console.log(
                  '[DeepLink] desired flow still not found; returning to home screen (2)'
                );
                Actions.reset('mainTabs');
              } else {
                console.log(
                  '[DeepLink] timer ended -- flow successfully fetched! (2)'
                );
              }
            }
          }, 5000);
        }
      }
    };
  }, []);

  console.log(props.flow_id);
  // Handle DeepLink
  return (
    <View>
      <Text>{props.flow_id}</Text>
    </View>
  );
};

export default DeepLink;
import React,{useffect}来自“React”;
从“react native”导入{链接、视图、文本};
从“react native router flux”导入{Actions};
从“react-redux”导入{useSelector,useDispatch};
从“../Router”导入路由器;
从“../reducers”导入减速机;
从“../actions”导入*作为ActionCreator;
从“../library/utils/Globals”导入*作为全局变量;
进口{
选择流,
flowsFetch,
亚流刻蚀,
}来自“../actions”;
const DeepLink=(道具)=>{
useffect(()=>{
const onDeepLink=(url)=>{
const dispatch=usedpatch();
const allFlows=useSelector(
(状态)=>state.flows.all
);
console.log(props.flow_id);
log(“[DeepLink]ondeplink:”,url);
const flow=allFlows.filter((obj)=>{
返回obj.key==url.key;
});
调度(flowsFetch());
如果(
allFlows.getState().app_bootstrap.completed==true
) {
log(“[DeepLink]引导已完成!”);
操作。重置(“主选项卡”);
if(url.hasOwnProperty('scene_key')){
log(“[DeepLink]场景_键存在”);
console.log(
“[DeepLink]流键:”,
url.flow\u键
);
//检查Deepline是否为规定流量
如果(
(props.flow\u id==url.scene\u key)===
“流程描述”&&
url.flow_key!==未定义
) {
log(“[DeepLink]场景_键是一个流!”);
console.log(
“[DeepLink]#存储区中具有匹配密钥的流:”,
流量长度
);
//如果未找到匹配密钥的流,请等待数据库获取
如果(flow.length==0){
console.log(
“[DeepLink]本地找不到流;正在启动计时器…”
);
调度(flowsFetch());
Actions.reset('notificationLoader'{
参数:url,
});
//等待流更新的计时器
设置超时(()=>{
//检查更新存储中的流
const updatedAllFlows=allFlows.getState()
.全部;
const updatedFlow=updatedAllFlows.filter(
(obj,索引)=>{
返回obj.key==url.flow\u键;
}
);
//如果仍然没有找到流,请回家
if(updatedFlow.length==0){
console.log(
“[DeepLink]仍未找到所需的流;返回主屏幕”
);
操作。重置(“主选项卡”);
}否则{
console.log(
“[DeepLink]计时器已结束--已成功获取流!”
);
}
}, 5000);
}否则{
log(“[DeepLink]流在本地找到!”);
//转到所选流
调度(选择流程(流程[0]);
派遣(
亚流刻蚀(
流[0]。流\u键,
(子流程)=>{
Actions.flowDescription({
flowCategory:flow[0]。flow\u类别,
标题:流[0]。标签,
持续时间:url.duration,
imageUri:流[0]。图像uri,
lock:url.lock,
动态支持:
url.dynamic\u packing\u支持,
选择支持:url.choice\u支持,
次级流动,
流量:流量[0],
});
}
)
);
}
//检查DeepLink是否为未定义流
}否则如果(
url.scene_key==='flowsdescription'&&
url.flow_key==未定义
) {
console.log(
“[DeepLink]错误:流键未定义”
);
//DeepLink不是一个流
}否则{
console.log(
“[DeepLink]场景_键不是流:”,
url.scene\u键
);
//尝试转到场景_键指定的屏幕
试一试{
动作[url.scene_key]();
}捕捉(错误){
console.log(
“[DeepLink]错误:无效的场景密钥”
);
}
}
}否则{
console.log(
“[DeepLink]场景密钥不存在”
);
}
}否则{
log(“[DeepLink]引导未完成!”);
如果(
url.hasOwnProperty('scene\u key')&&
url.scene_key!==“flowDescription”
) {
设置超时(()=>{
如果(
allFlows.getState().app\u引导
.completed==true
) {
console.log(
“[DeepLink]已完成屏幕的引导:”,
url.scene\u键
);
试一试{
动作[url.scene_key]();
}捕捉(错误){
console.log(
“[DeepLink]错误:无效的场景密钥”
);
}
}
}, 2000);
}否则如果(
url.hasOwnProperty('scene\u key')&&
(props.flow\u id==url.scene\u key)===
useEffect(()=>{
  //your code here
}, [props.flow_id])
useEffect(() => {
abc();
}, [dependency])

const abc = () => {
///function defination