Don't understand how reactive works #2866
Unanswered
sergeymild
asked this question in
General
Replies: 3 comments 3 replies
-
… On Fri, Mar 26, 2021 at 12:20 PM SergeyMild ***@***.***> wrote:
Hello i have a code
constComponent: React.FC = observer(() => {
cont store = useContext(MobxStore)
return (<FlatList data={store.items} renderItem={({item, index}) => <Text>{index}</Text>}/>)
})
class MobxStore {
constructor() {
makeAutoObservable(this)
}
@observable
items: Array<number> = []
removeItem = (index: number) => {
runInAction(() => this.items.splice(index, 1))
}
}
In that case the FlatList will not be updated, but if make a something
like that
constComponent: React.FC = observer(() => {
cont store = useContext(MobxStore)
const items = store.items
return (<FlatList data={items} renderItem={({item, index}) => <Text>{index}</Text>}/>)
})
FlatList will be updated.
What i did wrong? Thanks.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2866>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBCNYTIDSA47BVDTUU3TFR3YTANCNFSM4Z3JLYYA>
.
|
Beta Was this translation helpful? Give feedback.
3 replies
-
Sorry, section above it.
On Fri, Mar 26, 2021 at 12:24 PM Michel Weststrate ***@***.***>
wrote:
…
https://mobx.js.org/react-integration.html#callback-components-might-require-observer
On Fri, Mar 26, 2021 at 12:20 PM SergeyMild ***@***.***>
wrote:
> Hello i have a code
>
> constComponent: React.FC = observer(() => {
> cont store = useContext(MobxStore)
> return (<FlatList data={store.items} renderItem={({item, index}) => <Text>{index}</Text>}/>)
> })
>
> class MobxStore {
> constructor() {
> makeAutoObservable(this)
> }
>
> @observable
> items: Array<number> = []
>
> removeItem = (index: number) => {
> runInAction(() => this.items.splice(index, 1))
> }
> }
>
> In that case the FlatList will not be updated, but if make a something
> like that
>
> constComponent: React.FC = observer(() => {
> cont store = useContext(MobxStore)
> const items = store.items
> return (<FlatList data={items} renderItem={({item, index}) => <Text>{index}</Text>}/>)
> })
>
> FlatList will be updated.
> What i did wrong? Thanks.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#2866>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAN4NBCNYTIDSA47BVDTUU3TFR3YTANCNFSM4Z3JLYYA>
> .
>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello i have a code
If i will call
store.removeItem(1)
, In that case the FlatList will not be updated.But if make a something like that:
FlatList will be updated.
What i did wrong? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions