那是我得到的例外……这对我来说没有意义……
无效的挂钩调用。钩子只能在函数组件的主体内部调用。这可能是由于以下原因之一: 1. 你可能有不匹配的 React 版本和渲染器(例如 React DOM) 2. 你可能违反了 Hooks 规则 3. 你可能有多个 React 副本同一个应用程序请参阅 fb.me/react-invalid-hook-call 以获取有关如何调试和修复此问题的提示。
这是我的组件...我正在尝试仅存档标准登录/密码屏幕...
import React from 'react'
import { View, Text, TouchableWithoutFeedback, TextInput } from 'react-
native'
import style from './style'
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
import { faUser, faUnlockAlt } from '@fortawesome/free-solid-svg-icons'
import { Query, useMutation } from 'react-apollo'
import { testQuery, LOGIN_MUTATION } from '../../gql/session'
class LoginForm extends React.Component {
constructor(props) {
super(props)
this.state = {
inProgress: false,
email: 'hello@hello.com',
password: '1234'
}
}
doLogin() {
const [_doLogin ] = useMutation(LOGIN_MUTATION, {
update: (proxy, mutationResult) => {
console.log(mutationResult)
}
,
variables: {
$email: this.setState.email,
$password: this.state.password
}
})
_doLogin()
}
render() {
return (
<View style={style.form}>
<Text style={style.formLabel}>E-Mail</Text>
<View style={style.formRow}>
<FontAwesomeIcon size={28} style={style.formIcon} icon={faUser} />
<TextInput
onChangeText={(email) => this.setState({ email })}
value={this.state.email}
keyboardType={'email-address'}
style={style.textInput} />
</View>
<Text style={style.formLabel}>Password</Text>
<View style={style.formRow}>
<FontAwesomeIcon size={28} style={style.formIcon} icon={faUnlockAlt} />
<TextInput
onChangeText={(password) => this.setState({ password })}
value={this.state.password}
secureTextEntry={true}
style={style.textInput} />
</View>
<TouchableWithoutFeedback onPress={() => { this.doLogin() }}>
<View style={[style.button, style.doLoginButton]}>
<Text style={style.buttonText}>Login</Text>
</View>
</TouchableWithoutFeedback>
<View style={style.bellowButton}>
<TouchableWithoutFeedback onPress={() => this.props.onCancel()}>
<Text style={style.cancel}>Cancel</Text>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={() => this.props.onForgot()}>
<Text style={style.forgot}>Forgot ?</Text>
</TouchableWithoutFeedback>
</View>
</View>
)
}
}
export default LoginForm
那么,怎么了?以及如何存档?