反应原生功能组件和热重装不起作用

时间:2017-05-05 17:25:45

标签: react-native

在制作反应原生应用程序的过程中,我正在 React Native 中尝试函数式编程,出于某种原因,当我将预构建的代码转换为箭头函数时, HOT RELOADING 会做出响应,但不会推动更改,请提供帮助。

这是预先构建的代码w / class

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import Component1 from './app/components/msg/propsMsg'

export default class tutorial extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome a React Native Sandbox!
        </Text>
        <Component1 msg="props MSG"/>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{'\n'}
          Cmd+D or shake for dev menu
        </Text>
      </View>
    );
  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fefefe',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('tutorial', () => tutorial);

这是我尝试将其变为功能

const tutorial = () => {
  return (
    <View style={styles.container}>
      <Text style={styles.welcome}>
        Welcome a React Native Sandbox!
      </Text>
      <Component1 msg="props MSG 2"/>
      <Text style={styles.instructions}>
        Press Cmd+R to reload,{'\n'}
        Cmd+D or shake for dev menu
      </Text>
    </View>
  )
}

export default tutorial

0 个答案:

没有答案