3

I know there is the similar question here:

React-Intl How to use FormattedMessage in input placeholder

But I am using TypeScript.

this code:

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

ChildComponent.propTypes = {
  intl: intlShape.isRequired
}

does not work for me.

How to set this place holder with formatted message.

<InputPass
  placeholder="Enter password"
/>
Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116

1 Answers1

3

You can always use the formatMessage function from react-intl.

So you can do:

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

If your issue is more with typing injectIntl with typescript. You can do the following:

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

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

export default injectIntl<MyComponentProps>(MyComponent)

Note how we passed ComponentProps as a type argument so when you use the component from elsewhere typescript doesn't complain about the intl property not being passed.

sergioviniciuss
  • 4,596
  • 3
  • 36
  • 50
Christopher Chiche
  • 15,075
  • 9
  • 59
  • 98