@inject cause Expected a constructor.
i use reactNative
Is ok

cause

Any good ideas?
My configuration

Listening service

Same problem with fresh install of react-native, mobx and mobx-react. Did you find a workaround?
maybe related to this issue ? https://github.com/facebook/react-native/issues/24452
i getting same error :(
Yea, I would say it is definitely related to facebook/react-native#24452 and as such should be resolved there.
In case you don't want to wait for the fix, feel free to keep using mobx-react V5. As long as you write class components only, V6 doesn't give you much of the benefit.
Hey everyone, here is a fix you can add yourself that will work with RN >= 0.59 or Expo SDK 33.
- Create rn-cli.config.js in your base folder.
module.exports = {
transformer: {
babelTransformerPath: require.resolve('./scripts/customReactNativeTransformer')
}
};
- Create a file in your base folder called ./scripts/customReactNativeTransformer.js
Add the following:
const {
transform,
getCacheKey,
} = require('metro-react-native-babel-transformer/src/index);
function customTransform(config) {
config.options.hot = false;
return transform(config);
}
module.exports = {
transform: customTransform,
getCacheKey,
};
- Now you can use MobX@6!
I tried the solution provided by @stevelizcano , but it didn't work for me.
I did the following:
-
Created file
rn-cli.config.js, created folderscriptand created filecustomReactNativeTransformer.jsin this folder; -
I tried to install npm dependencies again, pod install and start (using commands
rm -rf node_modules/,npm i,pod installandnpm start -- --reset-cache), start iOS project using Xcode;
But the problem still exists, showing Expected a constructor.
Some configurations:
-
package.json:-
{ // some settings such as name, version are not shown here "dependencies": { "@babel/plugin-proposal-decorators": "^7.4.4", "babel-preset-react-app": "^9.0.0", "mobx": "^5.10.1", "mobx-react": "^6.1.1", "prop-types": "^15.7.2", "react": "16.8.3", "react-native": "0.59.9", // some other dependencies that I think not related to this issue }, "devDependencies": { "jest": "^24.8.0", "react-test-renderer": "16.8.3" }, "jest": { "preset": "react-native" }, "babel": { "plugins": [ [ "@babel/plugin-proposal-decorators", { "legacy": true } ] ], "presets": [ "react-app" ] } }
-
-
babel.config.js-
module.exports = { presets: ['module:metro-react-native-babel-preset'] };
-
-
jsconfig.json-
{ "compilerOptions": { "experimentalDecorators": true } }
-
Are there any important settings that haven't done here? Thank you!
Folks, this isn't really a bug caused by MobX (unless proven otherwise) and such you should be discussing it in react-native community. I appreciate posting pointers for passers-by, but let's not dwell into "it doesn't work for me" here. Thanks :)
my solution:
class Test extends Component {
···
}
export default inject("appStore")(observer(Test));
Hey everyone, here is a fix you can add yourself that will work with RN >= 0.59 or Expo SDK 33.
- Create rn-cli.config.js in your base folder.
module.exports = { transformer: { babelTransformerPath: require.resolve('./scripts/customReactNativeTransformer') } };
- Create a file in your base folder called ./scripts/customReactNativeTransformer.js
Add the following:
const { transform, getCacheKey, } = require('metro-react-native-babel-transformer/src/index); function customTransform(config) { config.options.hot = false; return transform(config); } module.exports = { transform: customTransform, getCacheKey, };
- Now you can use MobX@6!
hot reload will not available with this config