react选择和打字稿的自定义样式

问题描述 投票:0回答:1

我试图在我的打字稿react应用程序中设置我的react select组件的样式,但没有成功。当遵循文档:https://react-select.com/styles#provided-styles-and-state时,出现以下错误:

No overload matches this call.
  Overload 1 of 2, '(props: Readonly<ReactSelectProps<string>>): ReactSelectClass<string>', gave the following error.
    Type '{ control: () => { width: number; }; }' has no properties in common with type 'CSSProperties'.
  Overload 2 of 2, '(props: ReactSelectProps<string>, context?: any): ReactSelectClass<string>', gave the following error.
    Type '{ control: () => { width: number; }; }' has no properties in common with type 'CSSProperties'.  TS2769

代码示例:

const inputStyle = {
    control: () => ({

        width: 200,
      }),
<Select 
       name="Name"
       options={options}
       style={inputStyle}
 />

任何人都知道如何对打字稿使用自定义样式并做出选择反应?谢谢。

reactjs typescript react-select
1个回答
0
投票

您可以从'react'导入CSSProperties接口,并将重新运行值转换为CSSProperties

import React, {CSSProperties} from 'react'

control: () => ({
  width: 200,
} as CSSProperties)
© www.soinside.com 2019 - 2024. All rights reserved.