我在這裏問這個問題很瘋狂,但我找不到任何關於如何提交表單和捕獲RN數據的很好的教程。我發現的一切是有人推庫「只是npm安裝react-native-form-genie-magic-box並將其稱爲您的項目」...如何在React Native中提交表單
但我只想知道 - 如何提交香草形式React Native。
示例代碼:
AuthContainer
class AuthContainer extends Component {
render() {
const { errorMessage, handleLogin } = this.props
return (
<Login
errorMessage={errorMessage}
onLoginClick={(e) => handleLogin(e)}
/>
)
}
}
.....
const mapDispatchToProps = (dispatch) => {
return {
handleLogin: (e) => {
e.preventDefault()
const form = e.target
const data = serialize(form, {hash: true})
const creds = { email:data.email, password: data.password }
dispatch(loginUser(creds))
},
}
}
登錄
import { Container, Content, Form, Item, Input, Label, Button, Text } from 'native-base';
....
const Login = ({errorMessage, onLoginClick}) => {
return (
<Container>
<Content>
<Form >
{errorMessage &&
<Text>{errorMessage}</Text>
}
<Item floatingLabel>
<Label>Email</Label>
<Input
type="email"
name="email"
/>
</Item>
<Item floatingLabel last>
<Label>Password</Label>
<Input secureTextEntry={true} />
</Item>
<Button onPress={onLoginClick} ><Text>Sign in</Text></Button>
</Form>
</Content>
</Container>
)
}
問題:如何我剛剛捕獲AuthContainer的handleLogin
功能提交的電子郵件地址和密碼?
啊有趣。因此,RN中的方法是隻使用100%的受控輸入,每次更改後在其中保存輸入值,然後按下按鈕只需調用某些可以處理該數據的函數。我正在尋求一種不受控制的輸入方法,但這會起作用。謝謝你的好回答 – tim5046