What is the difference between React Native and React?

后端 未结 30 2589
粉色の甜心
粉色の甜心 2020-11-28 00:22

I have started to learn React out of curiosity and wanted to know the difference between React and React Native - though could not find a satisfactory answer using

30条回答
  •  醉梦人生
    2020-11-28 00:56

    In response to the comment from @poshest above, here is a React Native version of the Clock code previously posted in React (sorry, I was unable to comment on the section directly, otherwise I would have added the code there):

    React Native code sample

    import { AppRegistry } from 'react-native';
    import React, { Component } from 'react';
    import { View, Text, StyleSheet } from 'react-native';
    
    class Clock extends Component {
      constructor(props) {
        super(props);
        this.state = { date: new Date() };
      }
    
      componentDidMount() {
        this.timerID = setInterval(
          () => this.tick(),
          1000
        );
      }
    
      componentWillUnmount() {
        clearInterval(this.timerID);
      }
    
      tick() {
        this.setState({
          date: new Date()
        });
      }
    
      render() {
        return (
          
            Hello, world!
            It is {this.state.date.toLocaleTimeString()}.
          
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        backgroundColor: 'white',
        flex: 1,
        justifyContent: 'center',
      },
      sectionTitle: {
        fontSize: 24,
        fontWeight: '600',
        color: 'black',
        alignSelf: 'center',
      },
      sectionDescription: {
        marginTop: 8,
        fontSize: 18,
        fontWeight: '400',
        color: 'darkgrey',
        alignSelf: 'center',
      },
    });
    
    AppRegistry.registerComponent("clock", () => Clock);
    

    Note that the styling is entirely my choice and does not seek to replicate directly the

    and

    tags used in the React code.

提交回复
热议问题