如何解决装入页面时如何只发送一次?
下午好,亲爱的朋友们。现在,我已对所有操作执行调度。安装页面时我只需要调度一次,而卸载页面时将其删除。告诉我该怎么做。
const myRef = createRef<any>();
const KeyboardAvoidingWrapper: React.FC<IKeyboardAvoidingProps> = (
props: IKeyboardAvoidingProps,) => {
const dispatch = useDispatch();
dispatch(setReference(myRef));
if (isAndroid) {
return (
<ScrollView ref={myRef} style={styles.scroll} contentContainerStyle={styles.scrollContent}>
<KeyboardAvoiding>{props.children}</KeyboardAvoiding>
</ScrollView>
);
}
return (
<KeyboardAwareScrollView
ref={myRef}
style={styles.scroll}
extraHeight={40}
contentContainerStyle={styles.scrollContent}
>
{props.children}
</KeyboardAwareScrollView>
);
};
解决方法
尝试一下
// Similar to componentDidMount
useEffect(() => {
const dispatch = useDispatch();
dispatch(setReference(myRef));
return () => dispatch(deleteReference(myRef)); // delete here on unmount
},[]);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。