我收到以下错误消息:getInputData未定义

时间:2020-02-01 19:14:06

标签: reactjs react-native react-redux

我收到未定义getInputData的错误,请问我在做什么错呢? getInputData只是获取用户输入...。我正在使用redux。我在名为handleInput的函数中定义了getInputData,或者定义不正确……

import React from 'react';
import styles from './style';
import {Text} from 'react-native';
import {View,Input,InputGroup} from 'native-base';
import Icon from 'react-native-vector-icons/FontAwesome';
import { SearchBar } from 'react-native-elements';

export const SearchBox= ({getInputData}) => {
const handleInput= (key,val) =>{
getInputData({
key,
value:val
});
}
return(
<View style={styles.searchBox}>
<View style={styles.inputWrapper}>
<Text style={styles.label}>PICK UP</Text>
<InputGroup>
<Icon name="search" size={15} color="#FF5E3A"/>
<Input style={styles.inputSearch} placeholder="Enter Pickup Location"
onChangeText={handleInput.bind(this, "pickUp")}/>
</InputGroup>
</View>
<View style={styles.inputWrapper}>
<Text style={styles.label}>DROP OFF</Text>
<InputGroup>
<Icon name="search" size={15} color="#FF5E3A"/>
<Input style={styles.inputSearch} placeholder="Enter Drop Off Location"
onChangeText={handleInput.bind(this, "dropOff")}
/>
</InputGroup>
</View>
</View>
);
};
export default SearchBox;

这是我的mapContainer.js,其中inputData作为prop传递给SearchBox。

import React from 'react';
import styles from './style';
import {View} from 'native-base';
import MapView from 'react-native-maps';
import SearchBox from '../SearchBox';
import SearchResults from '../SearchResults';


export const MapContainer= ({region, getInputData}) => {

  return(
    <View style={styles.container}>
      <MapView
        provider={MapView.PROVIDER_GOOGLE}
        style={styles.map}
        region={region}
      >
      <MapView.Marker
        coordinate={region}
        pinColor="green"/>
      </MapView>
      <SearchBox getInputData={getInputData}/>
      <SearchResults/>
    </View>
  )
}

export default MapContainer

这是将mapStateToProps连接到mapActionCreators的地方

import {connect} from "react-redux";
import {
    getCurrentLocation,
        getInputData,
} from '../../actions/currentLocation';
import { MapContainer } from '../MapContainer';
import Home from "../../screens/Home";

const mapStateToProps=(state)=>({
    region:state.home.region,
    inputData:state.home.inputData || {}
});

const mapActionCreators = {
    getCurrentLocation,
    getInputData,
};

export default connect(mapStateToProps,mapActionCreators)(Home);

0 个答案:

没有答案