Making your own component - LucyMHall/Fizzy_O GitHub Wiki
- Make a directory called
components - make a file with the name of whatever your component does e.g.
FetchLocation.js - at the top of the file import React
import React from 'react': - then make the component:
const nameOfComponent = props => { return (); } - if you are using a Button component you have to improt it at the top e.g.
import {Button} from 'react-native';, then you can just refer to it in the component as `
Props
- allow for component customisation - adding parameters when created - these creation parameters are called props e.g. make a component for greeting people:
class Greeting extends Component {
render() {
return (
<View>
<Text> Hello {this.props.name}!</Text>
</View>
);
}
}
Then you can make a component that uses this component and supplies the name props value
<Greeting name="Lucy" />