【问题标题】:Invariant Violation: View config getter callback for component `div` must be a function (received `undefined`)不变违规:组件`div`的视图配置getter回调必须是一个函数(收到`undefined`)
【发布时间】:2022-01-22 02:19:35
【问题描述】:

我收到错误 - 不变违规:组件div 的视图配置getter 回调必须是一个函数(收到undefined)。确保以大写字母开头组件名称。 在下面的代码中,任何人都可以帮我找到错误吗? 所有组件都是大写,其余部分也被检查。

import React from "react";
import { Pressable, StyleSheet, Text, TouchableOpacity } from "react-native";
import { FlatList } from "react-native-web";

export default function ListItem(props) {
  const onDelete = (goalId) => {
    props.setCourseGoal((currGoal) => {
      return currGoal.filter((goal) => goal.key !== goalId);
    });
  };

  return (
    <FlatList
      data={props.courseGoal}
      keyExtractor={(item, index) => item.key}
      renderItem={(itemData) => (
        <TouchableOpacity
          activeOpacity={0.2}
          style={styles.touchList}
        >
          <Text style={styles.listData}>{itemData.item.value}</Text>
          <Pressable style={styles.closeBtn} title="Click Me !" onPress={onDelete.bind(this, itemData.item.key)}>
            <Text>❌</Text>
          </Pressable>
        </TouchableOpacity>
      )}
    />
  );
}

const styles = StyleSheet.create({
  touchList: {
    flexDirection: "row",
    marginVertical: 5,
  },

  listData: {
    width: "90%",
    textAlign: "center",
    padding: 10,
    borderRadius: 10,
    borderWidth: 1,
    marginHorizontal: 5,
  },
  closeBtn: {
    color: "black",
    justifyContent: "space-around",
    padding: 10,
    borderRadius: 10,
    borderWidth: 1,
  },
});

【问题讨论】:

    标签: react-native


    【解决方案1】:

    找到解决方案 - 它在第 3 行, import { FlatList } from "react-native-web"; 需要导入react-native

    【讨论】:

      猜你喜欢
      • 2021-10-05
      • 2022-12-28
      • 1970-01-01
      • 1970-01-01
      • 2021-06-27
      • 2020-11-11
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多