merhabalar
bir textimiz var. İçine ali yazıyor. altına bir butona koyduk ve bunu veli yaptırmak istedik mobx ile.
Yine bir tane MainStore.js oluşturuyoruz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import { observable, action, makeObservable } from "mobx"; class MainStore{ @observable name = 'ali desidero'; constructor() { makeObservable(this) } @action setName(name){ this.name = name; } } export default new MainStore(); |
sonra ilgili text ve butonumuzun olduğu sayfaya ilk önce importlarımızı yapıyoruz.
1 2 3 4 |
import { observable } from "mobx"; import { observer } from "mobx-react"; import MainStore from "../../Store/MainStore"; @observer |
text ve butonumuz
1 2 3 4 |
<Text>{MainStore.name}</Text> <TouchableOpacity onPress={()=> MainStore.setName("AliVeli")}> <Text>Değiştir</Text> </TouchableOpacity> |