Как получить React children offsetTop с помощью Typescript?
Вот моя составляющая:
export default class FadeIn extends Component {
private onScroll = () => {
React.Children.forEach(this.props.children, child => {
// Get the child's offsetTop here and do stuff with
})
}
public componentDidMount() {
window.addEventListener('scroll', this.onScroll)
}
public componentWillUnmount() {
window.removeEventListener('scroll', this.onScroll)
}
public render() {
return this.props.children
}
}
Я уже пробовал:
ReactDOM.findDOMNode(child), но я получаю Argument of type 'ReactChild' is not assignable to parameter of type 'ReactInstance'. Type 'string' is not assignable to type 'ReactInstance'getBoundingClientRect, но я получаю Property 'getBoundingClientRect' does not exist on type 'ReactChild'. Property 'getBoundingClientRect' does not exist on type 'string'ReactElement<any>Любая идея ?



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


1. попробуйте отправить ссылку на родительский компонент
2. сохранить ссылки в переменную или состояние
3. а затем в методе componentDidMount вы можете получить высоту дочернего компонента с помощью getBoundingClientRect.