我正在錯誤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 };
這可能需要一段時間,但一個安全可靠的方式來找到這個特定的錯誤就太記錄所有變量和發現的斷點的位置,即最後一個可記錄項目的下方。 – fungusanthrax
是否有任何其他選項,但降級反應原生 – Illep
哪個組件導致此問題 –