Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. export default class Input extends React.Component {
  2. componentDidMount() {
  3. // Set the initial input-value when first mounted.
  4. if (this.props.value !== undefined) {
  5. this.refs.input.value = this.props.value;
  6. }
  7. }
  8.  
  9. componentWillReceiveProps(props) {
  10. // Only update the input-value if the element is unfocused.
  11. if (props.value !== undefined && ReactDOM.findDOMNode(this.refs.input) !== document.activeElement) {
  12. this.refs.input.value = props.value;
  13. }
  14. }
  15.  
  16. render() {
  17. // Reproduce all attributes verbatim, except for "value".
  18. return <input ref="input" {...{...this.props, value: undefined}} />;
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement