Diskuze: React
V předchozím kvízu, Online test znalostí JavaScript, jsme si ověřili nabyté zkušenosti z kurzu.

Člen

Zobrazeno 7 zpráv z 7.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
V předchozím kvízu, Online test znalostí JavaScript, jsme si ověřili nabyté zkušenosti z kurzu.
Ahoj, vypadá to že ten NPM balíček nepodporuje "moderní" implementaci referencí v Reactu. inputRef je totiž prop do kterého musíš dát funkci, která v prvním argumentu obdrží právě danou referenci přímo na input. Viz: zde.
v konstruktoru přepiš
this.input = React.createRef();
Na
this.input = null;
A finálně u InputMask komponentu dej do propu inputRef funkci, která nastaví input na tu referenci co přijde v prvním argumentu. Třeba takhle:
inputRef={r => this.input = r}
Jo a focus voláš bez current, jelikož je to přímo cesta k té referenci. Takže jen
this.input.focus();
google = focus input React example
-> https://stackoverflow.com/…after-render
class App extends React.Component{
componentDidMount(){
this.nameInput.focus();
}
render() {
return(
<div>
<input
defaultValue="Won't focus"
/>
<input
ref={(input) => { this.nameInput = input; }}
defaultValue="will focus"
/>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('app'));
<input autoFocus type="text" />
componentDidMount() {
this.refs.linkInput.focus()
}
render: function() {
return (
<TextInput
ref={function(input) {
if (input != null) {
input.focus();
}
}} />
);
},
-----
render: function() {
return <TextInput ref={(c) => this._input = c} />;
},
componentDidMount: function() {
this._input.focus();
},
---
<input ref={ function(component){ React.findDOMNode(component).focus();} } />
---
const focusUsernameInputField = input => {
if (input) {
setTimeout(() => {input.focus()}, 100);
}
};
return (
<TextField
hintText="Username"
floatingLabelText="Username"
ref={focusUsernameInputField}
/>
);
díky moc. Teprve s Reactem začínám Funguje to skvěle, jen nevím,
jaký datový typ tomu přiřadit. Bez něj mi to nejde, tak jsem dal any.
private input:any;
Zobrazeno 7 zpráv z 7.