Ihar Hancharenka 5dff80e88e first
2023-03-27 16:52:17 +03:00

39 строки
1004 B
Plaintext
Исходник Ответственный История

Этот файл содержит невидимые символы Юникода

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

2019
https://moduscreate.com/blog/everything-you-need-to-know-about-refs-in-react/
https://rafaelquintanilha.com/the-complete-guide-to-react-refs/
2018
https://css-tricks.com/working-with-refs-in-react/
https://proglib.io/p/react-js-interview/
render() {
  var squareStyle = {
    backgroundColor: this.state.bgColor
  };
 
  var self = this;
 
  return (
    <div className="colorArea">
      <div style={squareStyle} className="colorSquare"></div>
 
      <form onSubmit={this.setNewColor}>
        <input onChange={this.colorValue}
               ref={ (el) => self._input = el; }
               placeholder="Enter a color value"></input>
        <button type="submit">go</button>
      </form>
    </div>
  );
}
...
setNewColor(e) {
  this.setState({
    bgColor: this.state.color
  });
 
  this._input.focus();
  this._input.value = "";
 
  e.preventDefault();
}