【发布时间】:2021-04-18 03:40:57
【问题描述】:
我的自定义输入组件收到以下警告:
'TextInput' refers to a value, but is being used as a type here. Did you mean 'typeof TextInput'?
当使用useRef 引用它时:
const lastNameRef = useRef<TextInput>(null)
TextInput 是这样的:
import React, { forwardRef } from "react"
import {
TextInput as ReactTextInput,
TextInputProps as ReactTextInputProps,
} from "react-native"
import styled from "styled-components/native"
import {
compose,
space,
SpaceProps,
color,
ColorProps,
layout,
LayoutProps,
flexbox,
FlexboxProps,
border,
BorderProps,
position,
PositionProps,
background,
BackgroundProps,
typography,
TypographyProps,
} from "styled-system"
export type TextInputProps = ReactTextInputProps &
SpaceProps &
ColorProps &
LayoutProps &
FlexboxProps &
BorderProps &
PositionProps &
BackgroundProps &
TypographyProps
const StyledTextInput = styled.TextInput<TextInputProps>`
${compose(
space,
color,
layout,
flexbox,
border,
position,
background,
typography,
)};
`
export const TextInput = forwardRef<ReactTextInput, TextInputProps>(
(
{
fontFamily = "body",
fontWeight = "regular",
fontSize = 1,
color = "text",
...rest
},
ref,
) => {
return (
<StyledTextInput
{...{ ref, fontFamily, fontWeight, fontSize, color, ...rest }}
/>
)
},
)
我正在转发参考资料,这就是应该摆脱该警告的原因。
有什么建议吗?
【问题讨论】:
标签: typescript react-native styled-components