React Native 0.61 中引入的快速刷新不起作用 [英] Fast refresh that was introduced in React Native 0.61 doesn't work
问题描述
(也发布在 https://github.com/facebook/react-native/issues/27583)
更新:一天过去了,我再次启动了我的应用程序.自发布问题以来没有改变任何东西.现在它工作正常.不知道发生了什么...从两个人将这个问题标记为有用的事实,我明白我不是唯一一个遇到这个问题的人......
我正在使用 React Native 0.61 运行一个非常基本的应用程序"(单个文件,单个组件),其代码附在下面.
I am running a very basic 'app' (a single file, a single component) for which the code is attached below, using React native 0.61.
使用 genymotion 在 Windows 10 上为 android 开发.
Developing for android, on windows 10 with genymotion.
快速刷新开启了,但是好像没有工作,例如,当:
Fast Refresh is turned on, but it doesn't seem to work, for example, when:
- 我正在将帖子"字符串更改为新帖子"
- 当我删除帖子按钮时
只有调试菜单的重新加载"会刷新应用并呈现更改.知道为什么吗?
Only the debug menu's "reload" refreshes the app and renders the changes. Any idea why?
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
}
});
推荐答案
我发现有时 Metro Bundler 会卡住".这就解释了为什么当你第二天运行它时,它运行良好.
I've found that sometimes the Metro Bundler gets 'stuck'. That would explain why when you ran it the next day, it worked fine.
当事情因为(似乎)没有明显原因而变得奇怪时,我会这样做:
When things get weird for (seemingly) no apparent reason, I do:
yarn start --reset-cache
这篇关于React Native 0.61 中引入的快速刷新不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!