【发布时间】:2016-08-30 04:28:43
【问题描述】:
在尝试使用react-rails 时,我遇到了将mobx 作为状态管理合并到我的应用程序中的问题。
我的印象是 rails 资产管道会引入 mobx 来做出反应,但是,这并没有成功。我正在使用 react-rails gem 并尝试将 mobx 合并到组件文件夹中的 react.es6.jsx 工作表中。
我的 package.json 文件:
{
"name": "rent-pseudo",
"version": "1.0.0",
"description": "== Zipqode",
"main": "index.js",
"dependencies": {
"babel-plugin-syntax-async-functions": "^6.3.13",
"babel-plugin-transform-regenerator": "^6.3.18",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babelify": "^7.2.0",
"bourbon": "^4.2.7",
"bourbon-neat": "^1.8.0",
"browserify": "^13.1.0",
"browserify-incremental": "^3.1.1",
"font-awesome": "^4.6.3",
"graphql": "^0.6.2",
"mobx": "2.4.1",
"mobx-react": "^3.5.3",
"mobx-react-devtools": "^4.2.5",
"react": "^15.3.1",
"react-dom": "^15.3.1",
"react-google-maps": "^4.11.0",
"react-router": "2.6.1",
"es6-promise": "^3.0.2",
"fetch": "^0.3.6",
"jquery": "^2.1.4",
"jquery-ujs": "^1.0.4"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://alexung@github.com/alexung/rent-pseudo.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/alexung/rent-pseudo/issues"
},
"homepage": "https://github.com/alexung/rent-pseudo#readme"
}
我的第一个反应文件包含在/components:
import { observer } from 'mobx-react'
const SearchResultsLayout = observer(React.createClass({
render: function() {
return (
<h1>Hello, World</h1>
)
}
}))
但我不断收到错误VM3275:1 Uncaught ReferenceError: SearchResultsLayout is not defined
有什么想法吗?
【问题讨论】:
-
为什么需要这个
package.json文件?我认为react-rails不需要它们。 -
SearchResultsLayout is not defined听起来像mobx本身正在工作(否则你会得到一个observer not defined)。您的组件调用站点上的导入语句是否正确? -
@mweststrate 你好!顺便说一句,我喜欢 mobX——我正在公司的一个项目中工作,但这更多是为了我个人的事情。对于如何将东西导入rails,我实际上非常天真。我为 React 所做的是使用 react-rails gem 创建一个组件文件夹,我可以在其中放置我的反应文件。但是,我对如何将 mobx 合并到其中感到困惑。当我尝试加入观察者时,我确实收到了
observer not defined错误。 -
我真的不知道。零经验的rails,下面的答案可能更有用;-)。
标签: javascript ruby-on-rails ruby reactjs mobx