在react-native中如何解决错误setNativeProps已弃用?

eulz3vhy  于 2023-03-24  发布在  React
关注(0)|答案(1)|浏览(448)

当我点击文本value.name模态显示。这是正确的,正是我想要的。
但是在控制台中,我有这个错误。

setNativeProps is deprecated. Please update props using React state instead.

我的代码:

import React, {useState} from "react";
import {Button, Text, View, TouchableOpacity} from "react-native";
import styles from "./styles";
import TextModal from "../Modal/TextModal";
import Modal from "react-native-modal";

const Placeholders = (props) => {
    const [isModalVisible, setIsModalVisible] = useState(false);
    const [numberClicked, setNumberClicked] = useState(-1);

    const toggleModalVisibility = (index) => {
        console.log(index);
        setIsModalVisible(!isModalVisible);
        setNumberClicked(index);
    };

    const showEveryValue = () => {
        let values = [];
        let keyCounter = 0;
        props.values.forEach((value) => {
            values.push(
                <View
                    key={keyCounter++}
                >
                    <Text
                        onPress={() => toggleModalVisibility(value.number)}
                    >
                        {value.name}
                    </Text>
                </View>
            );
        });
        return values;
    };

    return (
        <>
            {showEveryValue()}
            <Modal
                isVisible={isModalVisible}
                style={styles.modal}
            >
                <TouchableOpacity
                    onPress={() => toggleModalVisibility()}
                    style={styles.touchableOpacity}
                >
                    <TextModal
                        numberClicked={numberClicked}
                    />
                </TouchableOpacity>
            </Modal>
        </>
    );
};

export default Placeholders;

如何解决这个问题?
this page上我读到react-native包有问题。这是真的吗?还是错误在我的代码中?

jchrr9hc

jchrr9hc1#

根据your link,你是对的:截至2023-02-07,React Native团队正在解决这个问题。这个问题没有解决方案或变通方案。

相关问题