:
import React from 'react';
import { injectIntl, intlShape, defineMessages } from 'react-intl';
const messages = defineMessages({
placeholder: {
id: 'myPlaceholderText',
defaultMessage: '{text} and static text',
},
});
const ComponentWithInput = ({ intl, placeholderText }) => {
return (
<input
placeholder={ intl.formatMessage(messages.placeholder, { text: placeholderText }) }
/>
);
};
ComponentWithInput.propTypes = {
intl: intlShape.isRequired
};
export default injectIntl(ComponentWithInput);
とそれのuseage:
import ComponentWithInput from './component-with-input';
...
render() {
<ComponentWithInput placeholderText="foo" />
}
...
id: 'myPlaceholderText',
の部分は、翻訳のためにメッセージを収集できるようにするために必要です。
intlと注射は私のために働いた:http://stackoverflow.com/questions/33441524/how-to-use-formattedmessage-inside-an-option-tag-in-react-0-14 – Bryan