Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined is note an object(evaluating 'React.propTypes.func') #167

Open
JxSx opened this issue Sep 8, 2017 · 12 comments
Open

undefined is note an object(evaluating 'React.propTypes.func') #167

JxSx opened this issue Sep 8, 2017 · 12 comments

Comments

@JxSx
Copy link

JxSx commented Sep 8, 2017

image

Who can help me,please

my code:

import React from 'react';
import {View, Text, StyleSheet, Image, ViewPagerAndroid, Dimensions} from 'react-native';
import {requestLatestNews} from '../api/ZhiHuApi';

import ViewPager from 'react-native-viewpager';
const {width, height} = Dimensions.get('window');

export default class FindScreen extends React.Component{

  static navigationOptions = {
    tabBarLabel:'发现',
    tabBarIcon: ({ tintColor }) => (
      <Image
        source={require('../img/ic_tab_navi_normal.png')}
        style={[styles.icon, {tintColor: tintColor}]}
      />
    ),
  };

  constructor(props) {
    super(props);
    var dataSource = new ViewPager.DataSource({
      pageHasChanged: (p1, p2) => p1 !== p2,
    });
    this.state = {
      dataSource: dataSource.cloneWithPages([]),
    }
  }

  componentDidMount() {
    requestLatestNews().then(result => {
      this.setState({
        dataSource: this.state.dataSource.cloneWithPages(result.top_stories)
      });
    });
  }

  render(){
    return(
      <View style={{flex: 1}}>
        <ViewPager
          style={{flex:1}}
          dataSource={this.state.dataSource}
          renderPage={this._renderPage}
          isLoop={false}
          initialPage={0}
          renderPageIndicator={false}
          autoPlay={false}/>
      </View>
    );
  }

  _renderPage = (item) => {
    console.log(item)
    return (<Text>111</Text>);
  }

}

const styles = StyleSheet.create({
  icon: {
    width: 24,
    height: 24,
  },
  pageStyle: {
    alignItems: 'center',
    padding: 20,
    height: 100
  }
});
@gooddaddy
Copy link

我也遇到了同样的问题,你使用的react-native是什么版本的,我使用的是0.46.4

@bondanherumurti
Copy link

same problem here, i am using "react-native": "0.49.3"

@JxSx
Copy link
Author

JxSx commented Oct 24, 2017

@bondanherumurti "react-native": "^0.47.2"

@JxSx
Copy link
Author

JxSx commented Oct 24, 2017

@gooddaddy "react-native": "^0.47.2"

@GarveyCalvin
Copy link

@JxSx Same problem here, How to fix it? My react-native version is ''0.49.3"

@Jiahonzheng
Copy link

  • DefaultViewPageIndicator.js and ViewPager.js are using "React.PropTypes" instead of "PropTypes" imported from "prop-types". Issues 164
  • After we fixed the above trouble, we may encounter another error "React.createClass is not a function". If so, try to use "create-react-class" library. Hope it works for you!

@phatnguyenbg
Copy link

phatnguyenbg commented Dec 1, 2017

I also got an error with it and some guides below hope to help everyone fix it 💯
Reference: https://reactjs.org/blog/2017/04/07/react-v15.5.0.html#migrating-from-react.createclass
We take care 2 files: ViewPager.js and DefaultViewPageIndicator.js
The first one, we need to install more a package: npm install create-react-class --save
After that import 2 files like this: var createReactClass = require("create-react-class");
Also import: import PropTypes from "prop-types";
Replace ....createClass = createReactClass

DefaultViewPageIndicator.propTypes = {
goToPage: PropTypes.func.isRequired,
activePage: PropTypes.number.isRequired,
pageCount: PropTypes.number.isRequired
};
=> DefaultViewPageIndicator.js
And got it 👯‍♂️

@fastalks
Copy link

fastalks commented Dec 6, 2017

这个问题作者不更新修复吗?

@zhaoqigang
Copy link

I fork and fix it https://github.com/zhaoqigang/react-native-viewpager

@HS3
Copy link

HS3 commented Sep 8, 2018

听说是:这个组建已经过期了,很多api已经更新了,如果想继续用,那就等作者更新最新版本,rn项目中PropType的问题。等不了的朋友可以换 react native swiper

@spalanci
Copy link

import PropTypes from 'prop-types';

@joshington
Copy link

same problem i already have prop-types installed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests