-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAvailableStocksList.mixed.tsx
41 lines (34 loc) · 1.23 KB
/
AvailableStocksList.mixed.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React, { useEffect } from 'react';
import { FlatList } from 'react-native';
import { store } from '../../../../inject';
import { observer } from 'mobx-react-lite';
import AvailableStock from '../../../../business/state/AvailableStock';
import { AvailableStockContainer } from '../../AvailableStock.container';
export const AvailableStocksList_Mixed: React.FC<{}> = observer(() => {
useEffect(() => {
// On mount, we load the available stocks (the ones the user can buy)
// and then start listening to stock price updates.
(async () => {
await store.availableStocks.loadAvailableStocks();
store.availableStocks.startListeningToStockPriceUpdates();
})();
// On unmount, we stop listening to stock price updates.
return () => {
store.availableStocks.stopListeningToStockPriceUpdates();
};
}, []); // Run on mount only.
const renderItem = ({ item }: {
item: AvailableStock
}) => (
<AvailableStockContainer availableStock={item} />
);
return (
<FlatList
data={store.availableStocks.list.slice()}
scrollEnabled={true}
renderItem={renderItem}
keyExtractor={(item, _) => `stock-${item.ticker}`}
contentContainerStyle={{ flexGrow: 1 }}
/>
);
});