undefined不是函数(在'... React.createClass ...'附近)

布雷爱

我正在尝试使该库正常工作:https : //github.com/gcanti/tcomb-form-native

但是,当我在本地计算机上运行它时,出现错误: undefined is not a function (near '...React.createClass...')

我唯一能找到的提示是:https : //github.com/jayesbe/react-native-cacheable-image/issues/60,其中有人说React 16删除了createClass。

当我按照此处的步骤进行操作时https://reactjs.org/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactcreateclass

我收到一个涉及承诺的错误。我不太清楚如何使用此库,希望您能提供一些指导。

编辑:示例代码:

// index.ios.js

'use strict';

var React = require('react-native');
var t = require('tcomb-form-native');
var { AppRegistry, StyleSheet, Text, View, TouchableHighlight } = React;

var Form = t.form.Form;

// here we are: define your domain model
var Person = t.struct({
  name: t.String,              // a required string
  surname: t.maybe(t.String),  // an optional string
  age: t.Number,               // a required number
  rememberMe: t.Boolean        // a boolean
});

var options = {}; // optional rendering options (see documentation)

var AwesomeProject = React.createClass({

  onPress: function () {
    // call getValue() to get the values of the form
    var value = this.refs.form.getValue();
    if (value) { // if validation fails, value will be null
      console.log(value); // value here is an instance of Person
    }
  },

  render: function() {
    return (
      <View style={styles.container}>
        {/* display */}
        <Form
          ref="form"
          type={Person}
          options={options}
        />
        <TouchableHighlight style={styles.button} onPress={this.onPress} underlayColor='#99d9f4'>
          <Text style={styles.buttonText}>Save</Text>
        </TouchableHighlight>
      </View>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    justifyContent: 'center',
    marginTop: 50,
    padding: 20,
    backgroundColor: '#ffffff',
  },
  buttonText: {
    fontSize: 18,
    color: 'white',
    alignSelf: 'center'
  },
  button: {
    height: 36,
    backgroundColor: '#48BBEC',
    borderColor: '#48BBEC',
    borderWidth: 1,
    borderRadius: 8,
    marginBottom: 10,
    alignSelf: 'stretch',
    justifyContent: 'center'
  }
});
z

当您尝试这样做时会发生什么?

(PS这门课太老了……我可能建议不要使用这个库)

import React from 'react'
import { AppRegistry, StyleSheet, Text, View, TouchableHighlight } from 'react-native'
import t from 'tcomb-form-native'

var Form = t.form.Form

// here we are: define your domain model
var Person = t.struct({
  name: t.String,              // a required string
  surname: t.maybe(t.String),  // an optional string
  age: t.Number,               // a required number
  rememberMe: t.Boolean        // a boolean
})

var options = {} // optional rendering options (see documentation)

class AwesomeProject extends React.Component {
  constructor(props) {
    super(props)
    this.onPress = this.onPress.bind(this)
  }

  onPress() {
    // call getValue() to get the values of the form
    var value = this.refs.form.getValue()
    if (value) { // if validation fails, value will be null
      console.log(value) // value here is an instance of Person
    }
  }

  render() {
    return (
      <View style={styles.container}>
        {/* display */}
        <Form
          ref="form"
          type={Person}
          options={options}
        />
        <TouchableHighlight style={styles.button} onPress={this.onPress} underlayColor='#99d9f4'>
          <Text style={styles.buttonText}>Save</Text>
        </TouchableHighlight>
      </View>
    )
  }
}

var styles = StyleSheet.create({
  container: {
    justifyContent: 'center',
    marginTop: 50,
    padding: 20,
    backgroundColor: '#ffffff',
  },
  buttonText: {
    fontSize: 18,
    color: 'white',
    alignSelf: 'center'
  },
  button: {
    height: 36,
    backgroundColor: '#48BBEC',
    borderColor: '#48BBEC',
    borderWidth: 1,
    borderRadius: 8,
    marginBottom: 10,
    alignSelf: 'stretch',
    justifyContent: 'center'
  }
})

export default AwesomeProject

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Webpack构建React.createClass不是函数

React .createClass()滚动到引用:scrollIntoView不是函数

ReactJs CreateClass不是函数

React.createClass与ES6箭头函数

如何在React.createClass中使用箭头函数

React.createClass 不是函数,可能是 webpack 编译错误

undefined 不是函数(在'...datas.map ....'附近)

React.createClass与扩展组件

Render.js文件(电子应用程序)中的“未捕获的TypeError:React.createClass不是函数”

TypeError:undefined不是函数(在'... data.map ...'附近)

undefined不是函数(在'.... data.map ....'附近)|反应本机

TypeError:undefined不是函数(在'... this.state.profile.map ...'附近)

React.Component与React.createClass

React native undefined 不是函数

React Native扩展多个组件与createClass

未定义不是函数(在'... map ...'附近)

React Native undefined不是函数错误

.map(),Undefined不是React Native中的函数

如何扩展通过React.createClass创建的React组件类

:符号在React createClass()方法中意味着什么?

在点附近绘制隐函数

未定义不是_reactNavigation.StackNavigator附近的函数

未定义不是函数('...(0 _reactnavigation.stacknavigator)...'附近)

未定义不是函数('...(0,_reactNavigation.StackNavigator)...'附近)

未定义不是函数(在'... this.state.results.map ...'附近)

React Native Error:undefined不是一个函数(求值

(React-Native)undefined不是评估'new FormData()'的构造函数

在 React 中更改数组项的文本:undefined 不是函数

在不使用React.createClass的情况下使用props在react中播种初始状态