Skip to content

Commit 6c156bf

Browse files
committed
docs: Update Example in Readme to use hooks
1 parent 535d9d3 commit 6c156bf

File tree

1 file changed

+32
-46
lines changed

1 file changed

+32
-46
lines changed

README.md

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,39 @@ Start using the component
4242

4343
```jsx
4444
import MaterialTabs from 'react-native-material-tabs';
45+
```
46+
47+
## Usage
48+
49+
![Demo](https://user-images.githubusercontent.com/5962998/59991843-f2e43600-9616-11e9-913b-b8fb8a566d68.gif)
50+
51+
```jsx
52+
import React, { useState } from 'react';
53+
import { StyleSheet, SafeAreaView } from 'react-native';
54+
import MaterialTabs from 'react-native-material-tabs';
4555

46-
<MaterialTabs
47-
items={['One', 'Two', 'Three']}
48-
selectedIndex={this.state.selectedTab}
49-
onChange={index => this.setState({ selectedTab: index })}
50-
/>;
56+
const Example = () => {
57+
const [selectedTab, setSelectedTab] = useState(0);
58+
59+
return (
60+
<SafeAreaView style={styles.container}>
61+
<MaterialTabs
62+
items={['One', 'Two', 'Three', 'Four', 'Five']}
63+
selectedIndex={selectedTab}
64+
onChange={setSelectedTab}
65+
barColor="#1fbcd2"
66+
indicatorColor="#fffe94"
67+
activeTextColor="white"
68+
/>
69+
</SafeAreaView>
70+
);
71+
};
72+
73+
const styles = StyleSheet.create({
74+
container: {
75+
flex: 1,
76+
},
77+
});
5178
```
5279

5380
## Available Props
@@ -67,44 +94,3 @@ import MaterialTabs from 'react-native-material-tabs';
6794
| allowFontScaling | true | boolean | Specifies whether fonts should scale to respect Text Size accessibility settings |
6895
| uppercase | true | boolean | Specifies whether to uppercase the tab labels |
6996
| keyboardShouldPersistTaps | never | string | Specifies how the [ScrollView](https://facebook.github.io/react-native/docs/scrollview#keyboardshouldpersisttaps) should respond to taps while keyboard is open |
70-
71-
## Example
72-
73-
![Demo](https://user-images.githubusercontent.com/5962998/59991843-f2e43600-9616-11e9-913b-b8fb8a566d68.gif)
74-
75-
```jsx
76-
import React from 'react';
77-
import { StyleSheet, Text, SafeAreaView } from 'react-native';
78-
import MaterialTabs from 'react-native-material-tabs';
79-
80-
export default class Example extends React.Component {
81-
state = {
82-
selectedTab: 0,
83-
};
84-
85-
setTab = selectedTab => {
86-
this.setState({ selectedTab });
87-
};
88-
89-
render() {
90-
return (
91-
<SafeAreaView style={styles.container}>
92-
<MaterialTabs
93-
items={['One', 'Two', 'Three', 'Four', 'Five']}
94-
selectedIndex={this.state.selectedTab}
95-
onChange={this.setTab}
96-
barColor="#1fbcd2"
97-
indicatorColor="#fffe94"
98-
activeTextColor="white"
99-
/>
100-
</SafeAreaView>
101-
);
102-
}
103-
}
104-
105-
const styles = StyleSheet.create({
106-
container: {
107-
flex: 1,
108-
},
109-
});
110-
```

0 commit comments

Comments
 (0)