(也发表在https://github.com/facebook/react-native/issues/27583 https://github.com/facebook/react-native/issues/27583)
更新:一天过去了,我再次启动了我的应用程序。自从发布问题以来没有改变任何东西。现在效果很好。不知道发生了什么...
从两个人将这个问题标记为有用这一事实来看,我知道我并不是唯一一个遇到这个问题的人......
我正在运行一个非常基本的“应用程序”(一个文件,一个组件),其代码附在下面,使用 React Native 0.61。
使用 genymotion 在 Windows 10 上针对 Android 进行开发。
快速刷新 https://facebook.github.io/react-native/docs/fast-refresh已打开,但似乎不起作用,例如,当:
- 我正在将“帖子”字符串更改为“新帖子”
- 当我删除帖子按钮时
只有调试菜单的“重新加载”才会刷新应用程序并呈现更改。
知道为什么吗?
这是代码:
import React, { useState } from 'react';
import { View, TouchableOpacity, Text, StyleSheet } from 'react-native';
export const App = () => {
const [resource, setResource] = useState('todos');
return (
<View style={{ flex: 1, alignItems: 'center', marginTop: 30 }}>
<View style={{ flexDirection: 'row', marginTop: 0,
alignItems: 'center', justifyContent: 'center' }}>
<TouchableOpacity onPress={() => (setResource('posts'))}>
<View style={styles.button}>
<Text style={styles.buttonText}>
Posts
</Text>
</View>
</TouchableOpacity>
<View style={{ width: 20 }} />
<TouchableOpacity onPress={() => setResource('todos')}>
<View style={styles.button}>
<Text style={styles.buttonText}>
Todos
</Text>
</View>
</TouchableOpacity>
</View>
</View>
);
}
const styles = StyleSheet.create({
buttonText: {
color: 'black',
fontSize: 20
},
button: {
backgroundColor: '#a8a',
justifyContent: 'center',
alignItems: 'center',
paddingVertical: 5,
paddingHorizontal: 10,
borderRadius: 2
}
});