[英]how do I pass variables between functions?
Good afternoon, friends.下午好,朋友们。 I have two questions.
我有两个问题。
export function withScrollToFirstError(Component: t.form.Component): React.ComponentType { class ScrollToFirstErrorHOC extends PureComponent<OuterProps & PropsFromState, ComponentState> { constructor(props: OuterProps & PropsFromState) { super(props); this.state = { height: 0, offset: 0, }; } componentDidUpdate() { this.existError(); } existError = () => { const { currentFieldId, firstFieldId, arrayOfHeight, fieldOffset, fieldErrors } = this.props; this.calculateCoordinate(); }; calculateCoordinate = () => { const fullOffset = offset + fieldOffset[0]; this.scrollToRef(); }; scrollToRef = () => { if (this.props.reference) { this.props.reference.current.scrollTo({ x: 0, y: 0, animated: true, }); } };
Pass Fulloffset to the scrollToRef将 Fulloffset 传递给 scrollToRef
calculateCoordinate = () => {
const fullOffset = offset + fieldOffset[0];
this.scrollToRef(fullOffset); // like this
};
scrollToRef = (fullOffset) => {
if (this.props.reference) {
this.props.reference.current.scrollTo({
x: 0,
y: 0,
animated: true,
});
}
};
Declare props globally全局声明 props
export function withScrollToFirstError(Component: t.form.Component): React.ComponentType {
class ScrollToFirstErrorHOC extends PureComponent<OuterProps & PropsFromState, ComponentState> {
constructor(props: OuterProps & PropsFromState) {
super(props);
this.state = {
height: 0,
offset: 0,
};
// initialize here
this.arrayOfHeight = props.arrayOfHeight;
}
componentDidUpdate() {
this.existError();
}
existError = () => {
// use here like
this.arrayOfHeight;
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.