Сообщение от Alexandroppolus
|
я бы попробовал так:
const MobxFlatList = observer(FlatList)
|
Сделал так...
import React from "react"
import { StyleSheet, Text, View, Button, FlatList } from 'react-native'
import { observer} from 'mobx-react-lite'
import { toJS, runInAction } from "mobx"
import test from '../store/test'
function Test() {
//const arr = toJS(test.data.arr)
const renderItem = ({ item }) => (
<Text>{item.name}</Text>
)
const MobxFlatList = observer(FlatList)
return (
<View style={styles.container}>
<View style={styles.tab}>
<Button
title='Add'
onPress={add}
/>
</View>
<MobxFlatList
data={test.data.arr}
renderItem={renderItem}
keyExtractor={item => item.id}
/>
</View>
)
function add() {
const l = test.data.arr.length
test.add({
id: l.toString(),
name: 'Item ' + l
})
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
color: '#000',
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
tab: {
margin: 70
}
})
export default observer(Test)
Ошибка
Cannot call a class as a function