Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast refresh that was introduced in React Native 0.61 doesn't work

Tags:

react-native

(also posted in https://github.com/facebook/react-native/issues/27583)

Update: a day passed and I started my app again. Didn't change anything since posting the question. Now it works fine. No idea what happened... From the fact that two people marked this question as useful, I understand that I am not the only one having this problem...

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.

Developing for android, on windows 10 with genymotion.

Fast Refresh is turned on, but it doesn't seem to work, for example, when:

  1. I am changing the 'Posts' string to 'New Posts'
  2. When I remove the posts button

Only the debug menu's "reload" refreshes the app and renders the changes. Any idea why?

Here is the code:

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
  }
});
like image 820
Yossi Avatar asked Dec 20 '19 11:12

Yossi


1 Answers

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

like image 82
Zach G Avatar answered Sep 24 '22 12:09

Zach G