简体   繁体   English

TypeError: undefined is not a function(靠近'...currencyFilter.map...')

[英]TypeError: undefined is not a function (near '…currencyFilter.map…')

I'm quite new to react native and trying to set up a search bar with search functionality.我对本机反应并尝试设置具有搜索功能的搜索栏很陌生。 I'm trying to set it up where the list updates with each letter typed.我正在尝试将其设置在列表随键入的每个字母而更新的位置。 The data is displayed fine but the error occurs when I try and type something into the search bar.数据显示正常,但当我尝试在搜索栏中输入内容时出现错误。

Full Error Message完整的错误信息

https://ibb.co/Zd5hB52 https://ibb.co/Zd5hB52

Here is the file that is having issues这是有问题的文件

import { StyleSheet, Text, View, Button, StatusBar, ScrollView, TextInput } from "react-native";
import Icon from 'react-native-vector-icons/Ionicons';
import datas from "../components/CurrencyData"
import FavouritesList from "../components/FavouritesList";

const AddToFavourites = () => {

    const state = {
        datas: datas,
        filter: datas
    }

    const [currencyFilter, setSearch] = useState(state.filter)

    const getFlags = () => {
        return currencyFilter.map(data => {
            return <FavouritesList detail={data} key={data.id}/>
        })
    }

    const searchCurrencies = (searchFor) => {
        setSearch({
            filterCurrency: datas.filter(i=>
                i.name.toLowerCase().includes(searchFor.toLowerCase),
            ), 
        });
    }
    
    return (
        <View style={styles.container}>
            <View style= {styles.action}>
                <Icon name="search" size={25}/>

                <TextInput
                    style= {{flex: 1}}
                    placeholder= "Search..."
                    underlineColorAndroid="transparent"
                    onChangeText= {text => {searchCurrencies(text)}}
                />
            </View>

            <ScrollView>
                <StatusBar backgroundColor="#1E90FF" barStyle="light-content"/>
                {getFlags()}
            </ScrollView>
        </View>
        )
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: "center",
        justifyContent: "center",
    },
    action: {
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
        borderWidth: 2,
        height: 50,
        borderRadius: 30,
        paddingLeft: "4%",
        paddingRight: "4%",
        margin: "3%"
      },
})

export default AddToFavourites;```


  [1]: https://i.stack.imgur.com/kWkHo.png

with hooks you don't pass the state object like setState, you just pass the new value使用钩子,您不会像 setState 一样传递 state object,您只需传递新值

change改变

setSearch({
  filterCurrency: datas.filter(i => i.name.toLowerCase().includes(searchFor.toLowerCase)),
});

to

setSearch( datas.filter(I =>i.name.toLowerCase().includes(searchFor.toLowerCase)));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:未定义不是函数(靠近“...todos.map...”) - TypeError: undefined is not a function (near '...todos.map...') TypeError: undefined is not a function ('...data.map...'附近) - TypeError: undefined is not a function (near '…data.map…') React - “TypeError: undefined is not a function (near '...formFields.map...')” - React - “TypeError: undefined is not a function (near '…formFields.map…')” TypeError: undefined is not a function (near &#39;...productsCtg.map...&#39;) 反应原生 - TypeError: undefined is not a function (near '...productsCtg.map...') react native TypeError: undefined is not a function ('...this.state.profile.map...'附近) - TypeError: undefined is not a function (near '…this.state.profile.map…') React Native TypeError undefined is not a function(靠近'...data.map...') - React Native TypeError undefined is not a function (near '…data.map…') ReactJS TypeError: undefined is not a function (near '...this.state.data.map...') - ReactJS TypeError: undefined is not a function (near '...this.state.data.map...') 未定义不是 function(靠近'... map ...') - Undefined is not a function (near '… map …') TypeError:&#39;...} .bind(this)附近的表达式结果...&#39;&#39;[undefined]不是函数 - TypeError: Result of expression near '…}.bind(this))…' [undefined] is not a function React-Native - 错误类型错误:未定义不是 function(靠近'...object.Z1EZ8DC8ED512449E) - React-Native - ERROR TypeError: undefined is not a function (near '...object.map...')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM