首页 > 解决方案 > React Native - @emotion/native - TextInput 占位符文本颜色属性

问题描述

我试图通过函数传递placeholderTextColor属性。styled.TextInput.attrs我这样做的原因是我可以访问主题props

这就是我所拥有的:

const TextInput = styled.TextInput.attrs(props => ({
  placeholderTextColor: "red",
  type: "password"
}))`
  color: ${({ theme }) => theme.colors.text};
`

但我收到以下错误:

_native.default.TextInput.attrs is not a function. (In '_native.default.TextInput.attrs(function (props) {
    return {
      placeholderTextColor: "red",
      type: "password"
    };
  })', '_native.default.TextInput.attrs' is undefined)

标签: reactjsreact-nativeexpostyled-componentsemotion

解决方案


我猜@emotion/native还不支持这个attrs功能,所以我搬到了styled-components.


推荐阅读