Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@ndbx/runtime
Advanced tools
The @ndbx/runtime
package provides a runtime environment to embed NodeBox visualizations directly into React applications. NodeBox is a powerful tool for creating interactive and generative visualizations, and this runtime allows you to integrate those creations into your React-based web apps, controlling them dynamically from within your app’s logic.
To use the NodeBox runtime in your project, first install it using npm:
npm install @ndbx/runtime
To embed a NodeBox visualization into your React app, import the NodeBoxPlayer component and use it within your JSX. You’ll need a userId and projectId to specify which NodeBox project to load.
import { NodeBoxPlayer } from "@ndbx/runtime";
function App() {
return <NodeBoxPlayer userId="yourUserId" projectId="yourProjectId" />;
}
export default App;
Often, you’ll want to control the parameters of your NodeBox visualization dynamically. To do this, you can pass a handler function to the onProjectLoaded prop, which will be called once the project has loaded. You can also pass in a values object to define parameters dynamically.
import { useState } from 'react';
import { NodeBoxPlayer, Context, LiteralValue } from '@ndbx/runtime';
function App() {
const [values, setValues] = useState<Record<string, LiteralValue>>({});
function handleProjectLoaded(cx: Context) {
const main = cx.lookupItemByName('self/self/Main');
console.log(main.parameters); // Logs the available parameters
setValues({ fullName: "Frederik" }); // Example of setting a parameter
}
return (
<NodeBoxPlayer
userId="yourUserId"
projectId="yourProjectId"
onProjectLoaded={handleProjectLoaded}
values={values}
/>
);
}
export default App;
In this example, the handleProjectLoaded
function is used to retrieve information about the loaded project, and we can set parameters that the visualization will use. The setValues function updates the state of the parameters passed to the visualization.
string
): Your NodeBox user ID.string
): The ID of the project you wish to embed.string
): The name of the item to load in the project. Defaults to Main
.function
): A callback function that is triggered when the project has been successfully loaded. The Context object is passed to this function, which gives access to the project’s parameters and items.Record<string, LiteralValue>
): An object containing parameter values to dynamically update the project.Here’s a more complete example showing how you can use the NodeBoxPlayer in a typical React app:
import React, { useState } from 'react';
import { NodeBoxPlayer, Context, LiteralValue } from '@ndbx/runtime';
function App() {
const [name, setName] = useState("John Doe");
const [values, setValues] = useState<Record<string, LiteralValue>>({ fullName: name });
function handleProjectLoaded(cx: Context) {
const main = cx.lookupItemByName('self/self/Main');
console.log(main.parameters); // Logs parameters of the visualization
}
function updateName(newName: string) {
setName(newName);
setValues({ fullName: newName });
}
return (
<div>
<h1>Interactive NodeBox Visualization</h1>
<input
type="text"
value={name}
onChange={e => updateName(e.target.value)}
placeholder="Enter a name"
/>
<NodeBoxPlayer
userId="yourUserId"
projectId="yourProjectId"
onProjectLoaded={handleProjectLoaded}
values={values}
/>
</div>
);
}
export default App;
This example provides an interactive input that dynamically updates the fullName parameter in the NodeBox visualization.
The @ndbx/runtime
package allows you to control yout NodeBox visualizations from your React applications. For more information, consult the official NodeBox documentation or open an issue on GitHub if you have any questions or encounter any issues.
FAQs
## Introduction
We found that @ndbx/runtime demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.