[英]Click button programatically in react native
In my react-native app I have a screen where it contains a form.在我的 react-native 应用程序中,我有一个包含表单的屏幕。 I wanna submit the form on loading the screen because the values in form is gonna be constant.我想在加载屏幕时提交表单,因为表单中的值将保持不变。 So i wanna submit the form on loading.所以我想在加载时提交表单。 Is it possible?是否可以? Can someone help me..有人能帮我吗..
<PrimaryButton
// onPress={onSubmit(siteUrl)}
onPress={() => onSubmit(siteUrl)}
text={translate("general.enter")}
style={styles.buttonEnter}
mode={isSiteUrlSubmitted ? "loading" : undefined}
/>
i tried this onPress={onSubmit(siteUrl)} but it shows Invariant Violation: Too many re-renders.我试过这个onPress={onSubmit(siteUrl)}但它显示了不变违规:重新渲染太多。 React limits the number of renders to prevent an infinite loop. React 限制渲染次数以防止无限循环。
you can call onSubmit()
in React.useEffect
你可以在React.useEffect
调用onSubmit()
as such像这样
React.useEffect(() => {
onSubmit()
}, []);
When you add blank parentheses It will only be performed once in loading添加空括号时 加载时只会执行一次
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.