gpt4 book ai didi

reactjs - 如何在输入占位符中使用 FormattedMessage

转载 作者:搜寻专家 更新时间:2023-10-30 21:08:16 25 4
gpt4 key购买 nike

我知道这里有类似的问题:

React-Intl How to use FormattedMessage in input placeholder

但我正在使用 TypeScript。

这段代码:

import { injectIntl, intlShape } from 'react-intl';

ChildComponent.propTypes = {
intl: intlShape.isRequired
}

不适合我。

如何使用格式化消息设置此占位符。

<InputPass
placeholder="Enter password"
/>

最佳答案

您始终可以使用 formatMessage来自 react-intl 的功能。

所以你可以这样做:

<InputPass
placeholder={intl.formatMessage("messageKey")}
/>

如果您的问题更多在于使用 typescript 输入 injectIntl​​。您可以执行以下操作:

interface MyComponentProps {
/* non injected props */
}
interface MyComponentInjectedProps extends MyComponent {
intl: InjectedIntl;
}

class MyComponent extends Component<MyComponentInjectedProps, {}> {
...
}

export default injectIntl<MyComponentProps>(MyComponent)

请注意我们如何将 ComponentProps 作为类型参数传递,这样当您使用来自其他地方的组件时,typescript 不会提示未传递 intl 属性。

关于reactjs - 如何在输入占位符中使用 FormattedMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49568593/

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