Reactjs:错误消息未显示

时间:2018-02-14 00:56:20

标签: javascript reactjs electron materialize

我有一个非常简单的React情况,我在渲染函数中有一个错误,当状态更新为包含错误值时,没有任何内容被记录。当我检查生成的源时,数据错误属性正在更新,因此可能是materializeCSS的问题。控制台中没有显示错误。

我做错了什么?

    var {ipcRenderer, remote} = require('electron');  
var mainProcess = remote.require("./main.js");
class YouTubeDownloaderForm extends React.Component 
    {
      constructor(props) 
      {
        super(props);
        this.state = 
        {
          url: '', 
          urlInvalid: false,
          urlsInformation:[]
        };
        this.handleAddClick = this.handleAddClick.bind(this);
        this.handleSubmit = this.handleSubmit.bind(this);      
        this.handleChangeClick = this.handleChangeClick.bind(this);
        this.handleUrlChange = this.handleUrlChange.bind(this);
        this.updateUrlInformation = this.updateUrlInformation.bind(this);
      }
      componentDidMount() 
      {
        ipcRenderer.on('UrlInformation', this.updateUrlInformation)
      } 
      componentWillUnmount() 
      {
        ipcRenderer.removeListener('UrlInformation', this.updateUrlInformation)
      }

      updateUrlInformation(event, arg) 
      {
        if(arg=== false)
        {
          this.setState({urlInvalid: true});
          return;
        }
        this.setState({urlInvalid: false});

        var urlsInformation = this.state.urlsInformation;
        urlsInformation.push(arg);
        this.setState({urlsInformation: urlsInformation});
        this.setState({url: ''});
      }

      handleAddClick(event) 
      {      
        mainProcess.getUrlInformation(this.state.url);
      }
      handleUrlChange(event) 
      {
        this.setState({url: event.target.value});
      }
      handleChangeClick(event) 
      {
      }
      handleSubmit(event) 
      {
        event.preventDefault();
      }
      render() 
      {
        return (
          <form className="col s12" onSubmit={this.handleSubmit}>
            <div className="row">
              <div className="input-field">
                <input id="Url" type="text" value={this.state.url} className="validate" onChange={this.handleUrlChange}></input> 
                <label id="UrlLabel" htmlFor="Url" data-error={this.state.urlInvalid===true?'The entered url seems to be invalid. ':''}>Url</label>                     
              </div>          
        </div>
        </form>
        );
      }
    }
    ReactDOM.render(<YouTubeDownloaderForm/>, document.getElementById('root'));

enter image description here

2 个答案:

答案 0 :(得分:1)

我能够通过接管输入字段的验证来解决这个问题。希望这有助于某人。

即改变

02-14 12:31:54.574 25609-26777/com.test.vhp.testproject E/NanoHTTPD: Communication with the client broken, or an bug in the handler code java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 
 at android.os.Handler.<init>(Handler.java:200) 
 at android.os.Handler.<init>(Handler.java:114) 
 at android.widget.Toast$TN$3.<init>(Toast.java:350)
 at android.widget.Toast$TN.<init>(Toast.java:350) 
 at android.widget.Toast.<init>(Toast.java:107) 
 at android.widget.Toast.makeText(Toast.java:263) 
 at Server.serve(Server.java:34) at NanoHTTPD.NanoHTTPD$1.handle(NanoHTTPD.java:376) 
 at NanoHTTPD.NanoHTTPD$1.handle(NanoHTTPD.java:372) 
 at NanoHTTPD.NanoHTTPD.handle(NanoHTTPD.java:535) 
 at NanoHTTPD.HTTPSession.execute(HTTPSession.java:421) 
 at NanoHTTPD.ClientHandler.run(ClientHandler.java:75) 
 at java.lang.Thread.run(Thread.java:761) 
02-14 12:32:04.882 25609-26932/com.test.vhp.testproject E/NanoHTTPD: Communication with the client broken, or an bug in the handler code java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 
 at android.os.Handler.<init>(Handler.java:200) 
 at android.os.Handler.<init>(Handler.java:114) 
 at android.widget.Toast$TN$3.<init>(Toast.java:350) 
 at android.widget.Toast$TN.<init>(Toast.java:350) 
 at android.widget.Toast.<init>(Toast.java:107) 
 at android.widget.Toast.makeText(Toast.java:263) at Server.serve(Server.java:34)
 at NanoHTTPD.NanoHTTPD$1.handle(NanoHTTPD.java:376)
 at NanoHTTPD.NanoHTTPD$1.handle(NanoHTTPD.java:372) 
 at NanoHTTPD.NanoHTTPD.handle(NanoHTTPD.java:535) 
 at NanoHTTPD.HTTPSession.execute(HTTPSession.java:421)
 at NanoHTTPD.ClientHandler.run(ClientHandler.java:75) 
 at java.lang.Thread.run(Thread.java:761)

<input id="Url" type="text" value={this.state.url} className="validate" onChange={this.handleUrlChange}></input>

答案 1 :(得分:0)

ipcRenderer变量来自哪里?

你确定你的JS控制台是空的吗?

也许错误边界可以帮到你一点,检查https://reactjs.org/docs/error-boundaries.html