Skip to content

Commit ab3eb04

Browse files
authored
docs: update readme example (#208)
1 parent fa1b16a commit ab3eb04

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,41 @@ Contains many examples in the [example folder](https://github.com/vonovak/react-
2727
The corresponding code:
2828

2929
```tsx
30-
import React from 'react';
30+
import * as React from 'react';
3131
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
32-
import { Text } from 'react-native';
3332
import {
3433
HeaderButtons,
35-
HeaderButton,
3634
Item,
3735
HiddenItem,
3836
OverflowMenu,
37+
Divider,
38+
ItemProps,
39+
HiddenItemProps,
3940
HeaderButtonProps,
41+
HeaderButton,
4042
} from 'react-navigation-header-buttons';
43+
import { Text } from 'react-native';
4144

4245
const MaterialHeaderButton = (props: HeaderButtonProps) => (
4346
// the `props` here come from <Item ... />
4447
// you may access them and pass something else to `HeaderButton` if you like
4548
<HeaderButton IconComponent={MaterialIcons} iconSize={23} {...props} />
4649
);
4750

48-
const ReusableItem = ({ onPress }) => <Item title="Edit" onPress={onPress} />;
51+
const EditItem = ({ onPress }: Pick<ItemProps, 'onPress'>) => {
52+
return <Item title="edit" onPress={onPress} />;
53+
};
4954

50-
const ReusableHiddenItem = ({ onPress }) => (
51-
<HiddenItem title="hidden2" onPress={onPress} />
55+
const ReusableHiddenItem = ({ onPress }: Pick<HiddenItemProps, 'onPress'>) => (
56+
<HiddenItem title="hidden2" onPress={onPress} disabled />
5257
);
5358

5459
export function UsageWithIcons({ navigation }) {
55-
useLayoutEffect(() => {
60+
React.useLayoutEffect(() => {
5661
navigation.setOptions({
5762
title: 'Demo',
63+
// in your app, extract the arrow function into a separate component
64+
// to avoid creating a new one every time
5865
headerRight: () => (
5966
<HeaderButtons HeaderButtonComponent={MaterialHeaderButton}>
6067
<EditItem onPress={() => alert('Edit')} />
@@ -77,7 +84,7 @@ export function UsageWithIcons({ navigation }) {
7784
});
7885
}, [navigation]);
7986

80-
return <Text style={{ flex: 1 }}>demo!</Text>;
87+
return <Text>demo!</Text>;
8188
}
8289
```
8390

0 commit comments

Comments
 (0)