Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
react-native-web
Advanced tools
The react-native-web package allows you to use React Native components and APIs to build web applications. It provides a way to write a single codebase that can run on both mobile and web platforms, leveraging the same React Native components.
Cross-Platform Components
This feature allows you to use React Native components like View and Text to build web applications. The code sample demonstrates a simple app that displays 'Hello, world!' using React Native components.
import { View, Text } from 'react-native';
import { AppRegistry } from 'react-native-web';
const App = () => (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Hello, world!</Text>
</View>
);
AppRegistry.registerComponent('App', () => App);
AppRegistry.runApplication('App', { initialProps: {}, rootTag: document.getElementById('app') });
StyleSheet for Web
This feature allows you to use the StyleSheet API from React Native to style your web components. The code sample shows how to create and apply styles using StyleSheet.
import { StyleSheet, View, Text } from 'react-native';
import { AppRegistry } from 'react-native-web';
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});
const App = () => (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native Web!</Text>
</View>
);
AppRegistry.registerComponent('App', () => App);
AppRegistry.runApplication('App', { initialProps: {}, rootTag: document.getElementById('app') });
Event Handling
This feature allows you to handle events such as button presses using React Native's event handling system. The code sample demonstrates a button that shows an alert when pressed.
import { View, Button, Alert } from 'react-native';
import { AppRegistry } from 'react-native-web';
const App = () => (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Button
title="Press me"
onPress={() => Alert.alert('Button pressed!')}
/>
</View>
);
AppRegistry.registerComponent('App', () => App);
AppRegistry.runApplication('App', { initialProps: {}, rootTag: document.getElementById('app') });
react-native-dom is another package that aims to bring React Native to the web. It provides a similar set of components and APIs as react-native-web but focuses more on integrating with the DOM directly. It is less mature and has a smaller community compared to react-native-web.
react-primitives is a package that provides a set of primitive components that work across multiple platforms, including web, iOS, and Android. It is more lightweight compared to react-native-web and focuses on providing a minimal set of components for cross-platform development.
reactxp (React Cross-Platform) is a library developed by Microsoft that allows you to build cross-platform apps using React and React Native. It provides a unified API for building apps that run on web, iOS, Android, and Windows. It is more opinionated and comes with its own set of components and APIs.
"React Native for Web" makes it possible to run React Native components and APIs on the web using React DOM.
The documentation site (source) covers installation, guides, and APIs.
The examples app (source) demonstrates many available features. Fork the codesandbox to make changes and see the results.
You'll notice that there is no reference to react-dom
in components. The App
component that is shown below is defined using the APIs and Components of React Native, but it can also be rendered on the web using React Native for Web.
// Example component
import React from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
class App extends React.Component {
render() {
return (
<View style={styles.box}>
<Text style={styles.text}>Hello, world!</Text>
</View>
);
}
}
const styles = StyleSheet.create({
box: { padding: 10 },
text: { fontWeight: 'bold' }
});
AppRegistry.registerComponent('App', () => App);
AppRegistry.runApplication('App', { rootTag: document.getElementById('react-root') });
Development happens in the open on GitHub and we are grateful for contributions including bugfixes, improvements, and ideas. Read below to learn how you can take part in improving React Native for Web.
This project expects all participants to adhere to Meta's OSS Code of Conduct. Please read the full text so that you can understand what actions will and will not be tolerated.
Read the contributing guide to learn about the development process, how to propose bugfixes and improvements, and how to build and test your changes to React Native for Web.
To help you get you familiar with the contribution process, there is a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started.
React Native for Web is MIT licensed. By contributing to React Native for Web, you agree that your contributions will be licensed under its MIT license.
FAQs
React Native for Web
We found that react-native-web demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.