Skip to content

Commit 7618254

Browse files
committed
Prefer functional component
1 parent 1612eab commit 7618254

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

packages/react-router-native/NativeRouter.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,24 @@ import { Alert } from 'react-native'
66
* The public API for a <Router> designed for React Native. Gets
77
* user confirmations via Alert by default.
88
*/
9-
class NativeRouter extends React.Component {
10-
static propTypes = {
11-
initialEntries: PropTypes.array,
12-
initialIndex: PropTypes.number,
13-
getUserConfirmation: PropTypes.func,
14-
keyLength: PropTypes.number,
15-
children: PropTypes.node
16-
}
9+
const NativeRouter = (props) => (
10+
<MemoryRouter {...props}/>
11+
)
1712

18-
static defaultProps = {
19-
getUserConfirmation: (message, callback) => {
20-
Alert.alert('Confirm', message, [
21-
{ text: 'Cancel', onPress: () => callback(false) },
22-
{ text: 'OK', onPress: () => callback(true) }
23-
])
24-
}
25-
}
13+
NativeRouter.propTypes = {
14+
initialEntries: PropTypes.array,
15+
initialIndex: PropTypes.number,
16+
getUserConfirmation: PropTypes.func,
17+
keyLength: PropTypes.number,
18+
children: PropTypes.node
19+
}
2620

27-
render() {
28-
return <MemoryRouter {...this.props}/>
21+
NativeRouter.defaultProps = {
22+
getUserConfirmation: (message, callback) => {
23+
Alert.alert('Confirm', message, [
24+
{ text: 'Cancel', onPress: () => callback(false) },
25+
{ text: 'OK', onPress: () => callback(true) }
26+
])
2927
}
3028
}
3129

0 commit comments

Comments
 (0)