2017-10-19 72 views
1

我正在錯誤PropTypes已被廢棄,該如何解決呢

未定義不是對象(計算「_react2.PropTypes.string」)

在谷歌上搜索,我發現,React.Proptypes已被棄用,並且是獨立的。

但是,我該如何解決這個問題?

我嘗試以下:

1)npm install -g prop-types --save

2.)部分從代碼

import React, { Component } from 'react'; 
import PropTypes from 'prop-types'; 
import { Text, View, TouchableOpacity } from 'react-native'; 
import { Actions } from 'react-native-router-flux'; 
import { Field, reduxForm } from 'redux-form'; 
import { Container, Input, Button, Item, Spinner } from '../common'; 
import styles from './authStyle'; 

const propTypes = { 
    handleSubmit: PropTypes.func.isRequired, 
    clearState: PropTypes.func.isRequired, 
    signUpUser: PropTypes.func.isRequired, 
    authError: PropTypes.string.isRequired, 
    loading: PropTypes.bool.isRequired, 
}; 

class Signup extends Component { 
    constructor(props) { 
    super(props); 

    this.handleFormSubmit = this.handleFormSubmit.bind(this); 
    } 
... 

然而,我最終具有相同的錯誤和如何解決其?

UPDATE

import React from 'react'; 
import PropTypes from 'prop-types'; 
import { Text, TouchableOpacity } from 'react-native'; 

const propTypes = { 
    children: PropTypes.node.isRequired, 
    onPress: PropTypes.func.isRequired, 
    buttonStyle: PropTypes.object, 
    textStyle: PropTypes.object, 
}; 

const defaultProps = { 
    buttonStyle: {}, 
    textStyle: {}, 
}; 

function Button({ onPress, children, buttonStyle, textStyle }) { 
    const { button, text } = styles; 

    return (
    <TouchableOpacity 
     onPress={onPress} 
     style={[button, buttonStyle]} 
    > 
     <Text style={[text, textStyle]}> 
     {children} 
     </Text> 
    </TouchableOpacity> 
); 
} 

const styles = { 
    button: { 
    flex: 1, 
    alignSelf: 'stretch', 
    backgroundColor: '#039be5', 
    borderRadius: 3, 
    marginTop: 10, 
    }, 
    text: { 
    alignSelf: 'center', 
    color: '#fff', 
    fontSize: 16, 
    fontWeight: '600', 
    paddingTop: 10, 
    paddingBottom: 10, 
    }, 
}; 

Button.defaultProps = defaultProps; 
Button.propTypes = propTypes; 

export { Button }; 
+0

這可能需要一段時間,但一個安全可靠的方式來找到這個特定的錯誤就太記錄所有變量和發現的斷點的位置,即最後一個可記錄項目的下方。 – fungusanthrax

+0

是否有任何其他選項,但降級反應原生 – Illep

+0

哪個組件導致此問題 –

回答

-1

用這個代替

import PropTypes from 'prop-types'; 

Button.propTypes = { 
    type: PropTypes.string 
}; 
+0

我可以知道爲什麼這次投了票。我仍然在學習,如果有人能讓我知道原因,那也會很好。 – Illep

+0

你沒有給你的答案任何上下文,似乎你只是增加了'PropTypes'的用法。它看起來沒有什麼不同,然後OP如何使用。只是代碼或僅鏈接在SO中被認爲是低質量的答案。 – bennygenel

相關問題