Хотел подключить Mobx к проекту на React Native, чтобы получить данные с Laravel.
index.js
import axios from "axios";
import { makeAutoObservable } from "mobx";
import { React, createContext, useContext } from "react";
export class RootStore {
constructor() {
makeAutoObservable(this, {})
}
products = [];
*getProduct() {
try {
const response = yield axios.get('http://jsonplaceholder.typicode.com/todos/1') /// ссылка для примера
this.products = response.data
console.log(this.products)
} catch (error) {
console.log(error)
}
}
}
export const rootStore = new RootStore();
export const StoreContext = createContext(rootStore);
export const StoreProvider = StoreContext.Provider;
export const useStore = () => useContext(StoreContext)
Сама функция с observe
import { useEffect } from 'react';
import { useStore } from '../store';
import { observer } from 'mobx-react-lite';
const Category = observer(() => {
const store = useStore();
useEffect(() => {
store.getProduct()
}, [])
return ( ... )
}
)
export default Category
Ошибка в консоли
WARN Possible Unhandled Promise Rejection (id: 0):
TypeError: undefined is not a function
TypeError: undefined is not a function