Skip to content

Commit e6065f9

Browse files
author
prettifier[bot]
authored
Format bf86b28
1 parent bf86b28 commit e6065f9

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

README.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,57 +214,55 @@ https://facebook.github.io/react-native/docs/using-a-listview
214214
https://facebook.github.io/react-native/docs/network
215215

216216
```ts
217-
import React from 'react';
218-
import { FlatList, ActivityIndicator, Text, View } from 'react-native';
217+
import React from "react";
218+
import { FlatList, ActivityIndicator, Text, View } from "react-native";
219219

220-
221-
type DataItem = { title: string, releaseYear: string, id: string }
222-
type State = {
223-
isLoading: boolean,
224-
dataSource?: DataItem[]
225-
}
220+
type DataItem = { title: string; releaseYear: string; id: string };
221+
type State = {
222+
isLoading: boolean;
223+
dataSource?: DataItem[];
224+
};
226225
export default class FetchExample extends React.Component<{}, State> {
227-
228226
constructor(props) {
229227
super(props);
230-
this.state = { isLoading: true }
228+
this.state = { isLoading: true };
231229
}
232230

233231
componentDidMount() {
234-
return fetch('https://facebook.github.io/react-native/movies.json')
235-
.then((response) => response.json())
236-
.then((responseJson: {movies: any}) => {
237-
238-
this.setState({
239-
isLoading: false,
240-
dataSource: responseJson.movies,
241-
}, function () {
242-
243-
});
244-
232+
return fetch("https://facebook.github.io/react-native/movies.json")
233+
.then(response => response.json())
234+
.then((responseJson: { movies: any }) => {
235+
this.setState(
236+
{
237+
isLoading: false,
238+
dataSource: responseJson.movies
239+
},
240+
function() {}
241+
);
245242
})
246-
.catch((error) => {
243+
.catch(error => {
247244
console.error(error);
248245
});
249246
}
250247

251-
252-
253248
render() {
254-
255249
if (this.state.isLoading) {
256250
return (
257251
<View style={{ flex: 1, padding: 20 }}>
258252
<ActivityIndicator />
259253
</View>
260-
)
254+
);
261255
}
262256

263257
return (
264258
<View style={{ flex: 1, paddingTop: 20 }}>
265259
<FlatList
266260
data={this.state.dataSource}
267-
renderItem={({ item }) => <Text>{item.title}, {item.releaseYear}</Text>}
261+
renderItem={({ item }) => (
262+
<Text>
263+
{item.title}, {item.releaseYear}
264+
</Text>
265+
)}
268266
keyExtractor={({ id }, index) => id}
269267
/>
270268
</View>

0 commit comments

Comments
 (0)