You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native使用Redux-Form时keyboardType属性失效,是否有替代方案?

解决Redux-Form Field组件中keyboardType不生效的问题

Hey there! I see exactly what's going on here. You've set the keyboardType prop on your Redux-Form Field component, but your custom textAccount component isn't receiving and passing that prop down to the underlying Input from react-native-elements. That's why the keyboard type isn't updating as expected.

Here's how to fix it in two simple steps:

  1. Update your textAccount component to accept extra props
    Use the rest operator (...rest) to capture any additional props you pass to the Field component (like keyboardType), alongside the input and fieldName you're already using.

  2. Pass those extra props to the Input component
    Spread the rest props onto the Input so that React Native gets the keyboard type configuration.

Modified textAccount Component

import React from 'react';
import { View } from 'react-native';
import { Input } from 'react-native-elements';

function textAccount(props) {
  // Capture input, fieldName, and all other props with ...rest
  const { input, fieldName, ...rest } = props;
  
  return (
    <View>
      <Input
        // Bind Redux-Form's input handlers and value
        onChangeText={input.onChange}
        value={input.value}
        placeholder={fieldName}
        // Spread all extra props (including keyboardType) onto the Input
        {...rest}
      />
    </View>
  );
}

export default textAccount;

Your Field Usage (No Changes Needed!)

Your original Field component code is fine—once the textAccount component is updated, it will pick up the keyboardType prop automatically:

<Field 
  name="email" 
  component={textAccount} 
  fieldName="Email" 
  keyboardType="email-address" 
/>

Bonus: This approach works for other Input props too! You can now pass things like secureTextEntry for password fields, autoCapitalize, or maxLength directly through the Field component, and they'll be applied to the underlying input.

内容的提问来源于stack exchange,提问作者Flora

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:22:03