Undefined is not a function (rating "decorator (target, property, desc)")

I want to integrate mobx and mobx-persist with responsive-navigation .
I read these articles:

[1] https://hackernoon.com/react-navigation-with-mobx-2064fcdaa25b
[2] https://blog.callstack.io/write-react-native-apps-in-2017-style-with-mobx -e2dffc209fcb
[3] https://github.com/react-navigation/react-navigation/blob/8e8d3d562c9e80616f145f97ffb02dcf2048e67e/docs/guides/Mobx-Integration.md
[4] MobX + React 5: MobX + Reactative
5 : Why should I use `observer` when I can use` inject` when entering data into the React component
[6] Injection store in the React component leads to an error

But I still have this error:

undefined is not a function (evaluating 'decorator(target, property, desc)')

This is my rendering of App.js:

render() {
    const hydrate = create({
        storage: AsyncStorage
    });

    hydrate('playerStore', stores.PlayerStore);
    hydrate('settingStore', stores.SettingStore);
    // .then(
    //     // () => console.warn('some hydrated')
    // );

    return <Provider {...stores} >
        <AppWithNavigationState />
    </Provider>;
}

This is my routeStore.js:

import {observable} from "mobx";
import {action} from "mobx-react/native";
import AppDrawer from "../appDrawer";
import {autobind} from 'core-decorators';

export default class RouteStore {
    @observable.ref navigationState = {
        index: 0,
        routes: [
            { key: "R1", routeName: "ContentStack" },
        ],
    };

    @action
    dispatchNavigation(action, stackState = true) {
        const previousNavState = stackState ? this.navigationState : null;
        return this.navigationState = AppDrawer.router.getStateForAction(action, previousNavState);
    }
}

This is my appWithNavigationState.js:

import React from 'react';
import {observer, inject} from "mobx-react/native";
import {addNavigationHelpers} from "react-navigation";
import AppDrawer from "../appDrawer";

@inject(stores => ({ routeStore: stores.RouteStore }))
@observer
export default class AppWithNavigationState extends React.Component {
    render() {
        return (
            <AppDrawer navigation={addNavigationHelpers({
                dispatch: this.props.routeStore.dispatchNavigation,
                state: this.props.routeStore.navigationState,
            })} />
        );
    }
}

I also use a decorator package as shown below:

npm install babel-plugin-transform-decorators-legacy --save-dev

babelrc:

{
  "presets": ["react-native"],
  "plugins": ["transform-decorators-legacy"]
}

?

+4
1

React Native Babel ES7.

, :

npm install babel-plugin-transform-decorators-legacy --save-dev

.babelrc :

{
  "presets": ["react-native"],
  "plugins": ["transform-decorators-legacy"]
}
0

Source: https://habr.com/ru/post/1692937/


All Articles