Skip to content

Commit 0738ec8

Browse files
committed
fix(react): compatible babel configuration & React function component
move dependencies to devDependencies to avoid publish to npm
1 parent 9a1e736 commit 0738ec8

File tree

4 files changed

+15
-35
lines changed

4 files changed

+15
-35
lines changed

template/app/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import React from 'react'
33
import { StyleSheet, View, Text } from 'react-native'
4-
import <%= pascal %> from '<%= name %>'
4+
import { <%= pascal %> } from '<%= name %>'
55

66
export default () => (
77
<View style={styles.screen}>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
22
presets: ['module:metro-react-native-babel-preset'],
3-
};
3+
}

template/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint ./src --fix",
1212
"format": "prettier \"src/**/*\" --write"
1313
},
14-
"dependencies": {
14+
"devDependencies": {
1515
"@babel/core": "^7.15.0",
1616
"@babel/node": "^7.14.9",
1717
"@babel/preset-env": "^7.15.0",

template/src/index.js

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
11
// @flow
2-
import React, { Component } from 'react'
2+
import React, { useState } from 'react'
33
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native'
44

5-
export type Props = {
6-
initialCount: number,
7-
}
8-
9-
type State = {
10-
count: number,
11-
}
12-
13-
export default class <%= pascal %> extends Component<Props, State> {
14-
static defaultProps = {
15-
initialCount: 0,
16-
}
17-
18-
state = {
19-
count: this.props.initialCount,
20-
}
21-
22-
handlePress = () => {
23-
this.setState({
24-
count: this.state.count + 1,
25-
})
26-
}
27-
28-
renderThirdLayer(percent: number) {
5+
const ThirdLayer = ({ percent }) => {
296
if (percent > 50) {
307
return (
318
<View
@@ -36,29 +13,32 @@ export default class <%= pascal %> extends Component<Props, State> {
3613
}
3714

3815
return <View style={styles.offsetLayer} />
39-
}
16+
}
17+
18+
export type Props = {
19+
initialCount: number,
20+
}
4021

41-
render() {
42-
const { count } = this.state
43-
let percent = count % 100
22+
export const <%= pascal %> = ({ initialCount = 0 }: Props) => {
23+
const [count, setCount] = useState(initialCount)
24+
const percent = count % 100
4425

4526
return (
4627
<View style={styles.view}>
47-
<TouchableOpacity onPress={this.handlePress}>
28+
<TouchableOpacity onPress={() => setCount(count + 1)}>
4829
<View style={styles.container}>
4930
<View
5031
key={percent}
5132
style={[styles.firstProgressLayer, rotation(percent, -135)]}
5233
/>
53-
{this.renderThirdLayer(percent)}
34+
<ThirdLayer percent={percent} />
5435
<View pointerEvents="none" style={styles.textOverlay}>
5536
<Text style={styles.text}>{count}</Text>
5637
</View>
5738
</View>
5839
</TouchableOpacity>
5940
</View>
6041
)
61-
}
6242
}
6343

6444
const rotation = (percent: number, base: number) => ({

0 commit comments

Comments
 (0)