###前提・実現したいこと
electron + Reactで開発を行っています。
プログラミングに関しては初級者レベルのため、説明不足な部分や、意味が伝わらない部分があるかもしれませんが、お許しください。
electronのipcイベントで取得した引数をReactコンポーネントにSetState()して、画面に表示したいのですが、エラーが発生してしまい、解決方法がわかりません。
###発生している問題・エラーメッセージ
DeveloperToolに表示されたエラー
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the DrawImage component.
###該当のソースコード
"use stict"; const { remote } = require('electron'); const { Menu, MenuItem, dialog } = remote; const ipc = require('electron').ipcRenderer; ipc.on('fileOpen', function (event, array) { const drawImage = new DrawImage(); drawImage.setState({ image: array }); }); const ImageList = function (props) { return ( props.image.map(function (path, index) { <img key={index} src={path}></img> }) ); } class DrawImage extends React.Component { constructor(props) { super(props); this.state = { image: [] }; } render() { return ( <div> <ImageList image={this.state.image} /> </div> ); } } ReactDOM.render( <DrawImage />, document.getElementById('image') );
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/11 16:40