I wish to receive a message from backgroundJS of my chrome extension and change state of React DOM.
...
class App extends React.Component {
constructor() {
this.state = {
message: ''
};
}
func() {
chrome.runtime.sendMessage({type:"hello"})
}
render() {
return(
<div>{this.state.message}</div>
)
}
}
background.js
...
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.type == 'hello')
chrome.runtime.sendMessage({type:'How are you'});
})
How can I get the message from backgroundJS and change this.state.message to "How are you" received?