How do I add properties dynamically to this, taking an example from React docs on refs.
classCustomTextInputextendsReact.Component{constructor(props){super(props);this.textInput=null;this.setTextInputRef=element=>{this.textInput=element;};this.focusTextInput=()=>{// Focus the text input using the raw DOM APIif(this.textInput)this.textInput.focus();};}componentDidMount(){// autofocus the input on mountthis.focusTextInput();}render(){// Use the `ref` callback to store a reference to the text input DOM// element in an instance field (for example, this.textInput).return(<div><inputtype="text"ref={this.setTextInputRef}/><inputtype="button"value="Focus the text input"onClick={this.focusTextInput}/></div>);}}
If you say use ctx to dynamically attach things, that would just be no better than that = this and defeat the whole point you are making.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How do I add properties dynamically to
this
, taking an example from React docs on refs.If you say use
ctx
to dynamically attach things, that would just be no better thanthat = this
and defeat the whole point you are making.