Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class Input extends React.Component {
- componentDidMount() {
- // Set the initial input-value when first mounted.
- if (this.props.value !== undefined) {
- this.refs.input.value = this.props.value;
- }
- }
- componentWillReceiveProps(props) {
- // Only update the input-value if the element is unfocused.
- if (props.value !== undefined && ReactDOM.findDOMNode(this.refs.input) !== document.activeElement) {
- this.refs.input.value = props.value;
- }
- }
- render() {
- // Reproduce all attributes verbatim, except for "value".
- return <input ref="input" {...{...this.props, value: undefined}} />;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement