Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 0988fb5

Browse files
author
Igor Krasavin
authored
Update documents: Add examples with functional component (#1877)
1 parent 60c6302 commit 0988fb5

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

README.md

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ The simplest way to do this is to "CodePush-ify" your app's root component. To d
133133

134134
* **Option 1: Wrap your root component with the `codePush` higher-order component:**
135135

136+
* For class component
137+
136138
```javascript
137139
import codePush from "react-native-code-push";
138140

@@ -142,10 +144,23 @@ The simplest way to do this is to "CodePush-ify" your app's root component. To d
142144
MyApp = codePush(MyApp);
143145
```
144146

147+
* For functional component
148+
149+
```javascript
150+
import codePush from "react-native-code-push";
151+
152+
let MyApp: () => React$Node = () => {
153+
}
154+
155+
MyApp = codePush(MyApp);
156+
```
157+
145158
* **Option 2: Use the [ES7 decorator](https://github.com/wycats/javascript-decorators) syntax:**
146159

147160
*NOTE: Decorators are not yet supported in Babel 6.x pending proposal update.* You may need to enable it by installing and using [babel-preset-react-native-stage-0](https://github.com/skevy/babel-preset-react-native-stage-0#babel-preset-react-native-stage-0).
148161

162+
* For class component
163+
149164
```javascript
150165
import codePush from "react-native-code-push";
151166
@@ -154,18 +169,42 @@ The simplest way to do this is to "CodePush-ify" your app's root component. To d
154169
}
155170
```
156171

172+
* For functional component
173+
174+
```javascript
175+
import codePush from "react-native-code-push";
176+
177+
const MyApp: () => React$Node = () => {
178+
}
179+
180+
export default codePush(MyApp);
181+
```
182+
157183
By default, CodePush will check for updates on every app start. If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If an available update is mandatory, then it will be installed immediately, ensuring that the end user gets it as soon as possible.
158184

159185
If you would like your app to discover updates more quickly, you can also choose to sync up with the CodePush server every time the app resumes from the background.
160186

161-
```javascript
162-
let codePushOptions = { checkFrequency: codePush.CheckFrequency.ON_APP_RESUME };
187+
* For class component
163188

164-
class MyApp extends Component {
165-
}
189+
```javascript
190+
let codePushOptions = { checkFrequency: codePush.CheckFrequency.ON_APP_RESUME };
166191
167-
MyApp = codePush(codePushOptions)(MyApp);
168-
```
192+
class MyApp extends Component {
193+
}
194+
195+
MyApp = codePush(codePushOptions)(MyApp);
196+
```
197+
198+
* For functional component
199+
200+
```javascript
201+
let codePushOptions = { checkFrequency: codePush.CheckFrequency.ON_APP_RESUME };
202+
203+
let MyApp: () => React$Node = () => {
204+
}
205+
206+
MyApp = codePush(codePushOptions)(MyApp);
207+
```
169208

170209
Alternatively, if you want fine-grained control over when the check happens (like a button press or timer interval), you can call [`CodePush.sync()`](docs/api-js.md#codepushsync) at any time with your desired `SyncOptions`, and optionally turn off CodePush's automatic checking by specifying a manual `checkFrequency`:
171210
@@ -186,7 +225,7 @@ class MyApp extends Component {
186225
<TouchableOpacity onPress={this.onButtonPress}>
187226
<Text>Check for updates</Text>
188227
</TouchableOpacity>
189-
</View>
228+
</View>
190229
)
191230
}
192231
}

0 commit comments

Comments
 (0)