Redux形式。在这种环境中,赋值的来源必须是一个对象

时间:2017-08-08 07:25:57

标签: javascript react-native redux redux-form

我正在尝试将redux-form集成到我的react-native项目中。我正在关注这个例子(在文档中建议):

http://esbenp.github.io/2017/01/06/react-native-redux-form-immutable-styled-components/

但是,我按照它进入第3步,但我不断收到此错误:

  

在这种环境中,赋值的来源必须是一个对象。此错误是性能优化,不符合规范。

我真的很感激任何帮助或指示。

Form.js代码:

import React from 'react'
import { Field, reduxForm } from 'redux-form'

import {
  StyleSheet,
  Text,
  TextInput,
  TouchableOpacity,
  View
} from 'react-native'

const submit = values => {
  console.log('submitting form', values)
}

const renderInput = ({ input: { onChange, ...restInput }}) => {
  return <TextInput style={styles.input} onChangeText={onChange} {...restInput} />
}

const Form = props => {
  const { handleSubmit } = props

  return (
    <View style={styles.container}>
      <Text>Email:</Text>
      <Field name="email" component={renderInput} />
      <TouchableOpacity onPress={handleSubmit(submit)}>
        <Text style={styles.button}>Submit</Text>
      </TouchableOpacity>
    </View>
  )
}



const styles = StyleSheet.create({
  button: {
    backgroundColor: 'blue',
    color: 'white',
    height: 30,
    lineHeight: 30,
    marginTop: 10,
    textAlign: 'center',
    width: 250
  },
  container: {
    marginLeft:20,
  },
  input: {
    borderColor: 'black',
    borderWidth: 1,
    height: 37,
    width: 250
  }
})

export default reduxForm({
  form: 'test'
})(Form)

GitHub issue

0 个答案:

没有答案
相关问题