0

I am trying to build my first React Native app. I am using the default App.js code, the only difference is the output text that I changed from Open up App.js to Hello world!. I have an issue with the code changing itself upon save.

This is how the default function looks before I press Ctrl+S to save the file:

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Hello world!</Text>
    </View>
  );
}

And this is how the default function looks after the save:

export default function App() {
    return ( <
        View style = { styles.container } >
        <
        Text > Hello world! < /Text> <
        /View>
    );
}

Is it a bug or am I doing something wrong?

CircleMisty
  • 41
  • 1
  • 6

3 Answers3

1

This is based on your IDE. Since you are using Visual Studio Code as IDE try to use code formatting extension to format your code accordingly.

Try to use Prettier - Code Formatter Extension for VS Code -> Here

If you wan to enable auto save add the following to your settings.json file:

"editor.formatOnSave": true

If you wan to disable auto save add the following to your settings.json file:

"editor.formatOnSave": false

Akila Devinda
  • 5,054
  • 3
  • 19
  • 35
0

If you are using VS code... I got the same problem and I just solved it by:

  1. Click on the button in the bottom left probably saying "Javascript"
  2. Click on it and a search bar will appear
  3. Type "react" and choose each of the two either "react (javascriptreact)" or "react (typescriptreact)" depending on what you are using

Hope that helped solve your issue if not...

  1. ctrl+shift+p to open a the search bar
  2. type "open settings"
  3. click "open settings(JSON)"
  4. paste this at the end of the .json file: editor.formatOnSave": false
skara9
  • 4,042
  • 1
  • 6
  • 21
0

*Attention: Select the appropriate language mode.

Please see below for details:

Programming language: Javascript

Programming language: Javascript React