[英]How do you use mobx with react rails?
在嘗試使用react-rails時 ,我遇到了將mobx
作為狀態管理並入我的應用程序的問題。
我給人的印象是Rails資產管道會吸引mobx做出反應,但是,這並沒有成功。 我正在使用react-rails gem並嘗試將mobx合並到components文件夾中的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"
}
我的第一個react文件包含在/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
有任何想法嗎?
似乎您沒有通過以下方式在jsx文件中聲明React
import React from 'react'
或未安裝mobx軟件包
對於那些有興趣了解的人來說, react_on_rails gem更適合合並mobx。 今天早上可以通過簡單地安裝gem和npm將mobx安裝到client
文件夾中包含的我的package.json
使其工作
您可以從Rails資產中使用mobX
。 https://rails-assets.org/#/?query=mobx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.