React Native打车App报错:undefined is not an object(evaluating '_react2.Proptypes.store')
Hey there, let's break down the error you're hitting and get your app back on track. That error points directly to an issue with how you're using PropTypes in your AppContainer component. Here's what's going wrong and how to fix it:
Root Cause
Starting with React 16, the PropTypes utility was removed from the core React library. You've already installed the standalone prop-types package (I see it listed in your package.json), but your code is still trying to pull PropTypes from the react import—this means PropTypes ends up being undefined when you try to use PropTypes.object.isRequired, hence the error.
Step-by-Step Fix
1. Correct the PropTypes Import
Update your AppContainer component to import PropTypes from the standalone package instead of React:
import React, { Component } from "react"; import PropTypes from 'prop-types'; // Add this line, remove PropTypes from React import import { Router } from "react-native-router-flux"; import scenes from "../routes/scenes"; import { Provider } from "react-redux"; export default class AppContainer extends Component{ static propTypes = { store: PropTypes.object.isRequired } render(){ return( <Provider store = {this.props.store}> <Router scenes = {scenes} /> </Provider> ) } }
2. Double-Check Store Propagation
While the PropTypes fix should resolve the immediate error, make sure you're correctly passing the Redux store to AppContainer in your root component. For example:
// Example root component setup import { createStore, applyMiddleware } from 'redux'; import thunk from 'redux-thunk'; import rootReducer from './path/to/rootReducer'; // Your combined reducers import AppContainer from './path/to/AppContainer'; // Create your store with middleware const store = createStore(rootReducer, applyMiddleware(thunk)); // Render AppContainer with the store prop export default function Root() { return <AppContainer store={store} />; }
3. Verify Dependency Compatibility
Your react-native-router-flux version (4.0.0-beta.24) is a bit outdated, but it should work with React 16 and React Native 0.51. If you hit other issues after fixing PropTypes, you might consider updating it to a more stable release—but let's tackle the current error first.
Final Notes
After making these changes, rebuild your app (clear the Metro bundler cache if needed with react-native start --reset-cache) and test again. The PropTypes import fix is the critical one here—once that's sorted, the store prop validation should work as expected, and the error should disappear.
内容的提问来源于stack exchange,提问作者Prashant Chaulagain

