3 ms·
React began targeting the browser DOM. Now, React is actually the shared library used by both react-native and react-dom. In React (in general) you build comp
by grandalf 10y ago
React began targeting the browser DOM. Now, React is actually the shared library used by both react-native and react-dom.
In React (in general) you build components out of other components. Thus react-dom contains pre-defined components named after HTML dom elements. They behave like a very standards-compliant and consistent dom implementation.
So if you want to build a name badge component in React for web, you'd define a "render" method that used the dom-oriented components.
With React-Native, there was no reason to implement a component called Div. Instead, the authors created one called View. Instead of copying the browser DOM's behavior they created simple components that are fairly direct abstractions of native UI toolkit components... Things like ListView, Modal, etc. To build something using React Native, you just compose these existing components to make your own components.
Tangent: Interestingly, you can use a library called react-native-web to render React Native components in a browser, which makes it very elegant to share code between web and mobile versions of an app. There are a few differences, but it lets your pure js components designed for native work perfectly on the web, so it's actually not a bad approach for building for the web... in some cases React Native's components contain behavior you'd end up implementing for web anyway.