我正在开发一个 React 本机小部件。它由一个 View 组成,我想给这个 View 赋予与页面上具有特定类的另一个元素相同的颜色。
在 React(非本地)中,我会这样做:
componentDidMount(): void {
const otherElement = document.querySelector(".classOfElementThatIsNotInMyReactNativeWidget") as HTMLElement;
const thisComponent = this.Ref.current // I am getting the reference to my widget in the constructor using React.createRef();
thisComponent.style.backgroundColor = otherElement.style.backgroundColor
}
在 React native 中,我们没有文档,也无法进行 getElementById。
那么我该怎么做呢?
(是的,我是 React Native 的新手)
注意:棘手的是我正在为 Mendix 开发一个小部件。因此,我无法直接访问应用程序的其余部分,只能访问我的小部件中的组件。我想做的是“监听”我的小部件之外的另一个组件。