1

在尝试使用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

有任何想法吗?

4

3 回答 3

1

看来您要么没有通过以下方式在 jsx 文件中声明 React

import React from 'react'

或者 mobx 包没有安装

于 2016-08-30T21:55:48.797 回答
1

对于那些有兴趣了解的人,react_on_rails gem 更适合合并 mobx。今天早上只需将 gem 和 npm 安装 mobx 安装到我package.jsonclient文件夹中即可工作

于 2016-09-04T17:06:28.767 回答
0

您可以mobX从 Rails 资产中使用。 https://rails-assets.org/#/?query=mobx

于 2016-08-30T05:55:06.657 回答