Helper package for accessing embedded Gasket Data in the browser.
npm i @gasket/data
This helper is intended for use in conjunction with Gasket Data embedded in a script tag in the HTML document.
For example, if the following data is rendered...
<script id="GasketData" type="application/json">{ "something": "interesting" }</script>
...then it would be accessible as:
import gasketData from '@gasket/data';
console.log(gasketData.something); // interesting
To make data available for server-side rendering options, plugins should add to
the res.locals.gasketData
object.
For example when using the middleware lifecycle in a plugin:
module.exports = {
hooks: {
middleware() {
return (req, res, next) => {
res.locals.gasketData = res.locals.gasketData || {};
res.locals.gasketData.example = { fake: 'data' };
next();
}
}
}
};
The results of res.locals.gasketData
should then be rendering in a script as
described above.