gpt4 book ai didi

react-native - React Native TextInput 失去了对来自 useState 的调用钩子(Hook)的关注

转载 作者:行者123 更新时间:2023-12-04 10:54:10 24 4
gpt4 key购买 nike

环境

react 原生:“0.61.5”,

“样式组件”:“4.4.1”

转载

小吃示例:https://snack.expo.io/BJSfYqlCS

import * as React from 'react';
import styled from 'styled-components'
import {View} from 'react-native'

export default () => {
const [text, setText] = React.useState('');

const StyledInput = styled.TextInput`
background-color: red;
border-color: black;
`

return (
<View>
<StyledInput value={text} onChangeText={text => setText(text)} />
</View>
);
}

重现步骤

在样式化的 TextInput 中输入一些东西

预期行为

只是简单的打字

实际行为

失去焦点

最佳答案

使样式失去功能

import * as React from 'react';
import styled from 'styled-components'
import {View} from 'react-native'

const StyledInput = styled.TextInput`
background-color: red;
border-color: black;
`

export default () => {
const [text, setText] = React.useState('');

return (
<View>
<StyledInput value={text} onChangeText={text => setText(text)} />
</View>
);
}

查看 expo shack

关于react-native - React Native TextInput 失去了对来自 useState 的调用钩子(Hook)的关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59316565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com