0

我目前正在使用带有 nodejs 的 deepstream。现在,我正在按照这里的教程来使用新库:deepstream tutorial

但是,一旦我完成了文件的 RenderDOM 部分,就会出现错误。这是当前代码:

<!DOCTYPE html>
<html>
 <head>
<script src="deepstream.js"></script>
</head>
<body>
<input type="text" />
<script type="text/javascript">

    const deepstream = require('deepstream.io-client-js')
    const DeepstreamMixin = require('deepstream.io-tools-react')

    const client = deepstream('localhost:6020').login({}, () => {
      //ReactDOM.render call will go in here
      ReactDOM.render(
          <SyncedInput dsRecord="some-input" />,
          document.getElementById('example')
        )

        const SyncedInput = React.createClass({
          mixins: [DeepstreamMixin],
          setValue: function(e) {
            this.setState({value: e.target.value})
          },
          render: function() {
            return (
              <input value={this.state.value} onChange={this.setValue} />
            )
          }
        })
    })
    DeepstreamMixin.setDeepstreamClient(client)
</script>
</body>
</html>

错误显示在渲染中的这一行:函数:“输入值”

4

1 回答 1

0

You are missing the dependencies required for React. Right now that error is showing up because of invalid characters found in your javascript. Those characters are all part of React's meta language called JSX.

The tutorial assumes that you have set that up. There are two options for you:

  1. Use Webpack to preprocess your code such that all JSX are converted to proper JavaScript

  2. Load in browser transformers. See this tutorial for more information - https://www.sitepoint.com/getting-started-react-jsx/

I recommend going with #2 since that requires less setup.

于 2017-01-03T10:36:32.470 回答