【发布时间】:2017-06-01 07:06:54
【问题描述】:
我想创建一个简单的桌面应用程序,它使用 React JS 进行数据呈现。
但是,我对如此多的模块和技术感到不知所措。有一个 electron react boilerplate 对于像我这样的初学者来说非常复杂。
我有这些库的简单项目:
-
electron作为开发人员 reactreact-dom
我在启动电子的项目的根路径中有main.js,它取自this quickstart example
我有 index.html 应该加载我的 JSX 的文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<div id="react-view"></div>
</body>
<script type="text/jsx">
// You can also require other files to run in this process
require('./scripts/application');
</script>
</html>
有 scripts/application.js 文件,我的 JSX 将被填充到我的 <div id="react-view"></div>。
我的App.jsx很简单:
import React, {Component} from 'react'
class App extends Component{
render() {
return <h1>Hello From React</h1>;
}
}
export default App;
我的application.js 文件如下所示:
import React from 'react';
import ReactDom from 'react-dom/server';
import App from 'components/App';
ReactDom.render(<App/>, document.getElementById("react-view"));
当我启动我的电子应用程序时,它会打开一个内容为空的窗口,这意味着我的 JSX 没有加载。 而且它不会抛出任何错误信息
我错过了什么?
【问题讨论】:
-
您使用“react-dom/server”的任何具体原因?这对我来说似乎不同。我只是使用 react-dom。另外,您是否使用 webpack 之类的东西来捆绑 react 应用程序。浏览器不直接支持import,需要使用Babel转译。
-
@shashi 我刚刚阅读了一些文章并尝试使用它的代码。我不使用 webpack。
标签: javascript reactjs electron