语言环境处于我的 redux 应用程序状态。通过 react-devtools(revert 选项)更改其值,更改段落内部值,但不更改选择框值。如果它再次呈现,它不应该采用与 p 标签内相同的值吗?
import React, {Component, PropTypes} from 'react'
import {defineMessages, injectIntl, intlShape} from 'react-intl'
const messages = defineMessages({
spanish: {
id: 'languageSelector.spanish',
description: 'Select language',
defaultMessage: 'Spanish'
},
english: {
id: 'languageSelector.english',
description: 'Select language',
defaultMessage: 'English'
},
french: {
id: 'languageSelector.french',
description: 'Select language',
defaultMessage: 'French'
}
})
class LanguageSelector extends Component {
render () {
const {formatMessage, locale} = this.props.intl
return (
<div>
<select defaultValue={locale} onChange={(e) => this.handleChange(e)}>
<option id='es' value='es'>{formatMessage(messages.spanish)}</option>
<option id='fr' value='fr'>{formatMessage(messages.french)}</option>
<option id='en' value='en'>{formatMessage(messages.english)}</option>
</select>
<p>{locale}</p>
</div>
)
}
handleChange (e) {
this.props.onChange(e.target.value)
}
}
LanguageSelector.propTypes = {
intl: intlShape.isRequired,
onChange: PropTypes.func.isRequired
}
export default injectIntl(LanguageSelector)