How it works...

Let's check that everything is OK. We'll start by looking at the App.js file that was created by CRAN, and we can immediately verify that the tools work—because a problem is detected! Have a look at the following screenshot:

We can verify that ESLint integration is working, because it highlights a problem

The rule that fails is a new one, from eslint-plugin-react-nativeno-color-literals, because we are using constants in styling, which could prove to be a maintenance headache in the future. We can solve that by adding a variable, and we'll use a type declaration to make sure Flow is also running. The new code should be as follows—I've highlighted the required changes:

// Source file: App.original.fixed.js

/* @flow */


import React from "react";
import { StyleSheet, Text, View } from "react-native";

export default class App extends React.Component<> {
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Text>Changes you make will automatically reload.</Text>
<Text>Shake your phone to open the developer menu.</Text>
</View>
);
}
}

const white: string = "#fff";

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: white,
alignItems: "center",
justifyContent: "center"
}
});

So, now that we have restored all our tools, we can get started with actual code!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset