作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试找到使用 React 渲染的组件的位置。我使用的是 redux,所以我必须将 connect 函数修改为:
export default connect(mapStateToProps, mapDispatchToProps,null,{ withRef: true })(MyComponent);
现在,当我调用时,我会得到一个组件:
class OneColumn extends Component {
componentDidMount(){
var input = this.refs.myComponentsRef.getWrappedInstance();
console.log(input); // Outputs > TheComponentIWant {props: Object, context: Object, refs: Object, updater: Object, _reactInternalInstance: ReactCompositeComponentWrapper…}
var inputRect = input.getBoundingClientRect();
console.log(inputRect); // Outputs error: Uncaught TypeError: input.getBoundingClientRect is not a function
}
//...
}
所以我可以获取组件,但是我无法获取boundingClientRect。
我忽略了什么吗?
请帮忙:)
最佳答案
我找到了绕过此问题的替代解决方案:This post describes and refers to another post
基本上,当组件开始渲染时,组件会提供一个回调函数,您可以在其中存储这些组件的位置。
关于reactjs - React | 如何获取元素的位置Redux (.getBoundingClientRect() + .getWrappedInstance()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44519452/
我正在尝试找到使用 React 渲染的组件的位置。我使用的是 redux,所以我必须将 connect 函数修改为: export default connect(mapStateToProps, m
我正在用 typescript 写 React+Redux。我需要访问一个包装实例的引用,例如 this.refs.items.getWrappedInstance() , 但出现 typescrip
我注意到 @connect 实例上有一个名为 wrappedInstance 的属性,它包含用 @connect 包裹的组件状态。如果我使用它来访问状态如下 const { contact } = t
我是一名优秀的程序员,十分优秀!