
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
@untool/react
Advanced tools
@untool/react
@untool/react
provides all three types of @untool/core
mixins. Its core
mixin uses @untool/webpack
's configureBuild
hook to add some settings specific to React, for example support for JSX syntax.
Its runtime
, i.e. browser
and server
, mixins are a bit more interesting as they are untool
's only default render
mixins. They set up React for client- and server-side rendering. Additionally, they provide mixin hooks of their own to allow you to add your own features, for example Redux support.
$ yarn add @untool/react react react-dom react-router-dom react-helmet
# OR npm install @untool/react react react-dom react-router-dom react-helmet
render([req, res, next])
(override)This method is being called from within @untool/core
whenever you call its render
method. In a server-side, i.e. Node.js, environment it receives the usual arguments any Express middleware receives: req
, res
, and next
. In a client-side, i.e. browser, environment it receives no arguments whatsoever.
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
render(req, res, next) {
if (req) {
// server
} else {
// browser
}
}
};
You will not usually have to override this method as it exposes the following mixin hooks to alter its behaviour. In a server-side environment, a fresh mixinable
container is being created for every request, including new mixin instances.
bootstrap([req, res])
(parallel)Within this method, you are expected to set up your application. Your implementation will receive both Express' req
and res
objects for you to do whatever you like with. If you need to do something asynchronous in this method, just return a Promise
.
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
bootstrap(req, res) {
if (req) {
// server
} else {
// browser
}
}
};
Remember you can register custom middlewares using @untool/express
instead of implementing elaborate request or response handling logic inside your runtime mixin.
enhanceElement(element)
(compose)With this method, you can wrap the React root element with additional components, like Redux' Provider. If you need to do something asynchronous in this method, just return a Promise
resolving to the wrapped element.
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
bootstrap(element) {
return element;
}
};
fetchData(data, element)
(pipe)Most applications need some sort of data. Implement this method in your mixin, to fetch said data before rendering and return an object with that additional data. If you need to do something asynchronous in this method, just return a Promise
resolving to the data.
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
fetchData(data, element) {
return { ...data, foo: 'bar' };
}
};
getTemplateData(data)
(pipe, Server Only)In case you need to gather additional template data after React rendering, e.g. if you are using styled components, you can add the required data by implementing this hook in your custom mixin. To do so asynchronously, have this method return a Promise
resolving to the extended data.
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
getTemplateData(data) {
return { ...data, baz: 'qux' };
}
};
This hook is only used for server-side rendering, i.e. it will not be called in the browser.
FAQs
untool react mixin
The npm package @untool/react receives a total of 163 weekly downloads. As such, @untool/react popularity was classified as not popular.
We found that @untool/react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.