Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to target a dom element outside react native component

$
0
0

I am developing a React native widget. It consists of a single View and I want to give this View the same color as another element on the page with a specific class.

In React (no native) I would do this as follows:

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}

In React native, we do not have a document and cannot do getElementById.

So how can I do this, instead?

(yes, I am new to React native)

Note: The tricky thing is that I am developing a widget for Mendix. Consequently, I don't have direct access to the rest of the app, only to the components in my widget. What I want to do is to "listen" to another component that is outside of my widget.


Viewing all articles
Browse latest Browse all 6287

Trending Articles