Javascript 在React Native中自动提交Redux表单
有人知道在满足某些条件时如何在React Native中自动提交Redux表单吗?我下面的尝试是发出警告 文档中有一个例子,但是它使用HTML表单的Javascript 在React Native中自动提交Redux表单,javascript,reactjs,react-native,redux-form,Javascript,Reactjs,React Native,Redux Form,有人知道在满足某些条件时如何在React Native中自动提交Redux表单吗?我下面的尝试是发出警告 文档中有一个例子,但是它使用HTML表单的。这在React Native中的等效值是什么 我的尝试:当表单的输入长度>=2时提交 class MyClass extends React.Component { constructor(props) { super(props); this.handlSubmitWrapper = this.handlSubmitWrapp
。这在React Native中的等效值是什么
我的尝试:当表单的输入长度>=2时提交
class MyClass extends React.Component {
constructor(props) {
super(props);
this.handlSubmitWrapper = this.handlSubmitWrapper.bind(this);
}
handlSubmitWrapper() {
const { handleSubmit } = this.props;
handleSubmit(() => console.log('submitting...'))();
}
getTextInput({ input: { onChange, value, ...otherProps }, autoSubmit }) {
if (value && value.length > 1) {
// triger submit
autoSubmit();
}
return (
<TextInput
onChangeText={onChange}
style={{height: 50, backgroundColor: '#666'}}
{...otherProps}
maxLength={2}
/>
);
}
render() {
return (
<View>
<Field name="myText"
component={this.getTextInput}
autoSubmit={this.handlSubmitWrapper}
/>
</View>
);
}
}
const MyForm = reduxForm({
form: 'setupPasscode',
})(MyClass);
export default connect()(MyForm);
类MyClass扩展了React.Component{
建造师(道具){
超级(道具);
this.handlSubmitWrapper=this.handlSubmitWrapper.bind(this);
}
handlSubmitWrapper(){
const{handleSubmit}=this.props;
handleSubmit(()=>console.log('submitting…'))();
}
GetTestInput({input:{onChange,value,…otherProps},autoSubmit}){
如果(value&&value.length>1){
//触发器提交
自动提交();
}
返回(
);
}
render(){
返回(
);
}
}
const MyForm=reduxForm({
表格:“设置密码”,
})(MyClass);
导出默认连接()(MyForm);
警告:
ExceptionsManager.js:71警告:setState(…):无法在现有状态转换期间更新(例如在“render”或其他组件的构造函数中)。渲染方法应该是道具和状态的纯函数;构造函数的副作用是一种反模式,但可以移动到“componentWillMount”。
呈现组件时调用提交操作。你不能用react来做这件事。您应该改为使用TextInput onChange方法来实现这一点
类MyClass扩展了React.Component{
建造师(道具){
超级(道具);
this.handlSubmitWrapper=this.handlSubmitWrapper.bind(this);
this.handleInputChange=this.handleInputChange.bind(this);
}
handlSubmitWrapper(){
const{handleSubmit}=this.props;
handleSubmit(()=>console.log('submitting…'))();
}
handleInputChange(事件){
const newText=event.nativeEvent.text;
如果(newText&&newText.length>1){
//触发器提交
this.handlSubmitWrapper();
}
}
GetTestInput({input:{onChange,value,…otherProps}}){
返回(
);
}
render(){
返回(
);
}
}
const MyForm=reduxForm({
表格:“设置密码”,
})(MyClass);
导出默认连接()(MyForm);
呈现组件时调用提交操作。你不能用react来做这件事。您应该改为使用TextInput onChange方法来实现这一点
类MyClass扩展了React.Component{
建造师(道具){
超级(道具);
this.handlSubmitWrapper=this.handlSubmitWrapper.bind(this);
this.handleInputChange=this.handleInputChange.bind(this);
}
handlSubmitWrapper(){
const{handleSubmit}=this.props;
handleSubmit(()=>console.log('submitting…'))();
}
handleInputChange(事件){
const newText=event.nativeEvent.text;
如果(newText&&newText.length>1){
//触发器提交
this.handlSubmitWrapper();
}
}
GetTestInput({input:{onChange,value,…otherProps}}){
返回(
);
}
render(){
返回(
);
}
}
const MyForm=reduxForm({
表格:“设置密码”,
})(MyClass);
导出默认连接()(MyForm);