在React Native中使用日期时间选择器时出现问题

kx1ctssn  于 6个月前  发布在  React
关注(0)|答案(1)|浏览(200)
import {
  View,
  Text,
  Button,
  TextInput,
  ScrollView,
  StyleSheet,
} from "react-native";
import DateTimePicker from "@react-native-community/datetimepicker";

import React, { useState } from "react";

export const CreateTaskScreen = () => {
  const [state, SetState] = useState({
    title: "",
    description: "",
    date: "",
  });

  const SetData = (key, value) => {
    SetState({
      ...state,
      [key]: value,
    });
  };

  const HandlePress = () => {
    console.log(state);
  };

  return (
    <View>
      <Text>Crear tarea</Text>
      <TextInput
        placeholder="Title"
        onChangeText={(value) => SetData("title", value)}
      ></TextInput>
      <TextInput
        placeholder="Description"
        multiline
        numberOfLines={4} // Adjust the number of lines as needed
        onChangeText={(value) => SetData("description", value)}
      ></TextInput>
      <DateTimePicker
        style={{ width: 200 }}
        date={new Date()}
        mode="date"
        placeholder="select date"
        format="YYYY-MM-DD"
        onDateChange={(value) => SetData("date", value)}
      ></DateTimePicker>
      <Button title="Save" onPress={HandlePress}></Button>
    </View>
  );
};

字符串
我收到错误Invariant Violation:TurboModuleRegistry.getEnforcing(...):'RNCDatePicker' could not be found.验证此名称的模块已在本机二进制文件中注册。,js引擎:爱马仕
我不知道为什么会发生这种情况。
我已经用过了:

yarn add @react-native-community/datetimepicker


在package.JSON中,我有:

"@react-native-community/datetimepicker": "^7.6.1",

1hdlvixo

1hdlvixo1#

React Native应用中的错误“Invariant Violation:TurboModuleRegistry.getEnforcing(...):'RNCDatePicker' could not be found”通常表示本机模块注册表或链接存在问题。
以下是您可以采取的一些步骤来排除故障并解决问题:

重新构建原生模块:

尝试为您的项目重新构建本机模块。在项目目录中运行以下命令:

npx react-native unlink
npx react-native link

字符串
这将取消链接,然后重新链接所有本机模块。之后,再次尝试运行您的应用。

清除构建工件:

有时候,构建构件可能会导致问题。请尝试清除构建构件,然后重新构建项目:

npx react-native clean
npx react-native run-android  # for Android
npx react-native run-ios      # for iOS

手动连接模块:

如果问题仍然存在,请尝试手动链接模块:
对于Android:

npx react-native link @react-native-community/datetimepicker


对于iOS:

npx react-native link @react-native-community/datetimepicker
cd ios && pod install


请确保将**@react-native-community/datetimepicker**替换为您正在使用的实际软件包名称。

相关问题