How to set an ID in react-native-web

Aaron MGDR
Aug 9, 2019 · 1 min read

(in hindsight obvious, while trying not so)

So a few months ago, I wanted to set an `id` on a react-native-web (RNW) View component <View id="newsletter"/> But that doesnt work.

Turns out in order to maintain compatibility with ReactNative, RNW uses `nativeID` This is in the docs, but I somehow missed it, until i found this issue https://github.com/necolas/react-native-web/issues/1116

So to set an ID on a view in react native web, which will be mapped to the elements dom node do this


<View nativeID="some-id" />

docs referencing this are here

https://necolas.github.io/react-native-web/storybook/?selectedKind=Components&selectedStory=View&full=0&addons=0&stories=1&panelRight=0

More From Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade