The problem
"id" attribute of View element was lost in Browser's DOM - since react-native-web@0.8.0.
How to reproduce
Simplified test case: https://codesandbox.io/s/xjpnqj2l4o
Steps to reproduce:
RED box - which include the text "Hey, just text!"Expected behavior
The RED box should have attribute id="should-exist-in-dom" in Browser's DOM - but it won't.
Environment (include versions). Did this work in previous versions?
Still work fine in @0.7.3 and older one.. in that codesandbox example - change react-native-web version back to @0.7.3 (package.json) will fix that, and we'll see id="should-exist-in-dom" as we should.
That's not supported anymore. The release notes for 0.8.0 describe the change
@necolas thanks for the info.. couldn't we just add "id" to the whitelist?
I think it is an important attribute and we'll need that to play well with legacy Web library from our react-native-web website.
How are you using id?
I made web-based application using react-native-web (with server-side-rendering), like this.
There will be chance that we need to mark an element with the id attribute and use it in hybrid with legacy javascript library..
And sometime, on server side stuffs, e.g. crawling bot may expect that our site have element marked by id instead of class.
A quick example, when I'm trying to add particles.js to one of the site.. particle.js is using id internally _(document.getElementById)_ to select the element we want to apply the particle effect to.
_in this particular case, we could make pull request to the library which add support for class - cause it quite simple, but I belive we can't always do that._
You can set native attributes using the setNativeProps API, or use <div>, or use the createElement API. I don't think bots have any real expectations about id.
For your use case I think you can create a separate component that doesn't use RNW and uses div to bind your particle library. Then you can import that into RN components without directly leaking DOM details.
One area I think id could be useful is in use with certain aria properties, but usually accessibilityLabel is sufficient.
@necolas yep, you convinced me.
at first - it seem inconvenient when couldn't just use id directly like I could - but after a while I agree that I didn't really need that like I thought.
Thanks for your great work ;)
Hello guys !!!! it's useful for anchor link ;)
There's nativeID. It's in the docs
Most helpful comment
@necolas yep, you convinced me.
at first - it seem inconvenient when couldn't just use
iddirectly like I could - but after a while I agree that I didn't really need that like I thought.Thanks for your great work ;)