![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
react-document-modifier
Advanced tools
Declaritive, nested, stateful `document` modification for React applications
#React Document Modifier
Provides declaritive, nested, stateful document
modification for React applications.
Inspired by React Document Title. Built with React Side Effect.
Often we want to modify our document
node's children (e.g. <head>
and <body>
), which are outside the scope of our React application.
For example, you may want to add a class to <body>
to prevent overflow scrolling when a modal is visible; or you may want to update the page title using document.title
, when a new component is mounted (e.g. at routing).
Direct node manipulation is discouraged, as it can cause the DOM to get out-of-sync with our React application state.
DocumentModifier
is a higher-order component that takes an Object of { property: value }
pairs and sets them on the document
node. The Object is passed from within your components, ensuring that your application always owns the state of modifications.
document
;props
and state
;Warning: this has not been tested in isomorphic/universal environments.
$ npm install --save react-document-modifier
Dependencies:
"dependencies": {
"lodash": "^3.10.0",
"react": "^15.0.0",
"react-side-effect": "^1.0.0",
"seamless-immutable": "^5.0.0"
},
DocumentModifier takes one required prop called properties
, which is an object
. The object provides the properties and values you want to set, with respect to document
.
document.title
)To apply: document.title = "My Web App"
<DocumentModifier properties={{title: 'My Web App'}}>...</DocumentModifier>
document.body.class
)To apply: document.body.class = "noscroll"
const modifications = {
body: {
class: 'noscroll'
}
};
<DocumentModifier properties={modifications}>...</DocumentModifier>
var App = React.createClass({
render: function () {
// Will apply "My Web App" to `document.title`, if no child overrides it
return (
<DocumentModifier properties={{title: 'My Web App'}}>
<HomePage />
</DocumentModifier>
);
}
});
var HomePage = React.createClass({
render: function () {
// Will overwrite any parent title property and use "Home", while this component is mounted
return (
<DocumentModifier properties={{title: 'Home'}}>
<h1>Home, sweet home.</h1>
</DocumentModifier>
);
}
});
var NewArticlePage = React.createClass({
render: function () {
// While this component is mounted, the title will update using a value from state
// It will also add the class 'article-page' to `document.body.class`
return (
<DocumentModifier properties={{title: this.state.title || 'Article', body: {class: 'article-page'}}}>
<div>
<h1>New Article</h1>
</div>
</DocumentModifier>
);
}
});
lodash
and seamless-immutable
MIT - see LICENSE
<head>
?Check out React Helmet! to modify document.head
.
Observant build an integrated platform for the precision management of water in agriculture. We're hiring engineers, say hello at @obsrvnt or visit http://www.observant.net/careers/ for more.
FAQs
Declaritive, nested, stateful `document` modification for React applications
We found that react-document-modifier demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.