Я пытаюсь получить простую ссылку, используя React.createRef()
. Но всегда возвращается {current: null}
.
Я посмотрел здесь React-createRef () Api - this.child.current равен нулю и здесь тип потока React ref callback и createRef , а также в официальной документации, но я всегда получай { current: null }
.
мой компонент:
export class FormDialog extends TpComponent<FormDialogProperties, FormDialogState> {
protected template: any = require('./form-dialog.rt');
protected style: any = require('./form-dialog.scss');
public domReference: React.RefObject<{}>;
public constructor(props: FormDialogProperties, state: FormDialogState) {
super(props, state, false);
this.state = new FormDialogState();
this.domReference = React.createRef();
console.log(this.domReference);
}
// ....
и шаблон (с использованием react-templates
):
<div class="tp-form {this.layout}" rt-if="this.state.isVisible" ref={this.domReference} >
Как я уже говорил выше, ссылка всегда null
. Я также пытался зарегистрировать ссылку в других методах жизненного цикла (например, componentDidMount
или render
), но ни один из них не работал. Это всегда { current: null }
. Что мне здесь не хватает?