How can I use React.DOM to change styles on HTML body
?
I tried this code and it\'s not working:
var MyView = React.createClass({
rende
Assuming your body tag isn't part of another React component, just change it as usual:
document.body.style.backgroundColor = "green";
//elsewhere..
return (
Stuff goes here.
);
It's recommended to put it at componentWillMount
method, and cancel it at componentWillUnmount
:
componentWillMount: function(){
document.body.style.backgroundColor = "green";
}
componentWillUnmount: function(){
document.body.style.backgroundColor = null;
}