React Native Textinput 不会在 iOS 上调用 onchange

发布于 2025-01-11 10:55:39 字数 531 浏览 3 评论 0原文

我的反应本机应用程序有问题。我有简单的注释输入,它在 Android 上按预期工作,但在 iOS 上永远不会调用 onChange/onChangeText 方法。这很奇怪,因为我在输入中看到正确的值,但如果我在 onChange 方法中 console.log ,它永远不会被调用。我在这里缺少什么?

const [noteEdit, _setNoteEdit] = useState(note)
const noteRef = React.useRef(noteEdit);

const setNoteEdit = event => {
        const note= event.nativeEvent.text;
        _setNoteEdit(note);
        noteRef.current = note;
    }

<TextInput multiline={true} 
                value={noteEdit} onChange={setNoteEdit} autoCorrect={false} />

I have a problem with my react-native app. I have simple input for the note, it works as expected on Android, but on iOS onChange/onChangeText method is never called. It is weird because i see correct value in input, but if I console.log in onChange method, its never called. What am I missing here?

const [noteEdit, _setNoteEdit] = useState(note)
const noteRef = React.useRef(noteEdit);

const setNoteEdit = event => {
        const note= event.nativeEvent.text;
        _setNoteEdit(note);
        noteRef.current = note;
    }

<TextInput multiline={true} 
                value={noteEdit} onChange={setNoteEdit} autoCorrect={false} />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赢得她心 2025-01-18 10:55:39

你需要尝试下面的方法希望它有效

 const [noteEdit, _setNoteEdit] = useState('')

<TextInput multiline={true} 
            value={noteEdit} onChangeText={(text)=>_setNoteEdit(text)} autoCorrect={false} />

you need to try this below hope it's working

 const [noteEdit, _setNoteEdit] = useState('')

<TextInput multiline={true} 
            value={noteEdit} onChangeText={(text)=>_setNoteEdit(text)} autoCorrect={false} />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文