Как получить смещение типа React для детей, используя 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>
Есть идеи?