score:5
the best/simplest solution would be to have a stub index.html file which includes the scripts that you need (you could install libraries from npm as others has suggested, however this will work for libraries which only have a cdn). thus you would have an index.html
file like this:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>navigating spinoza</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.js"></script>
<script src="http://marvl.infotech.monash.edu/webcola/cola.v3.min.js"></script>
<script src="http://maurizzzio.github.io/greuler/greuler.min.js"></script>
</head>
<body>
<div id="root"></div>
<div class="row" id="demo"></div>
</body>
</html>
and then a react component like like this (i have moved some code around to better follow some react idioms):
var component = react.createclass({
componentdidmount:function() {
greuler({
target: '#chart',
width: 480,
height: 500,
data: {
nodes: [
{id: 0, label: "e1def3", r: 25},
{id: 1, label: "e1p4", r: 15},
{id: 2, label: "e1p2", r: 15},
{id: 3, label: "e1p1", r: 15},
{id: 4, label: "e1p5", r: 15},
{id: 5, label: "e1p6", r: 25}
],
links: [
{source: 0, target: 1, directed: true},
{source: 0, target: 2, directed: true},
{source: 0, target: 3, directed: true},
{source: 1, target: 4, directed: true},
{source: 2, target: 5, directed: true},
{source: 3, target: 4, directed: true},
{source: 4, target: 5, directed: true}
]
}
}).update()
}
render() {
return (
<div id="chart"></div>
);
}
}
reactdom.render(<component />, document.queryselector('root'));
this is a simple solution that could stand to do more (such as use react's state and properties to pass around parameters) but this should give a general idea of the solution. this code also assumes that you have included the react and reactdom libraries in some way (babel, cdn, etc.).
score:0
try installing the module with npm:
npm install greuler
see here: https://www.npmjs.com/package/greuler
then use in your component:
var greuler = require('greuler')
score:0
you need to use a module bundler like webpack or browserify and then import the library.
npm install greuler
var greuler = require('greuler')
score:0
i got an issue like this, but the old answers cannot run. so i create this here.
url
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.js"></script>
<script src="https://fastly.jsdelivr.net/npm/webcola@3.4.0/webcola/cola.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/greuler@1.0.0/dist/greuler.min.js"></script>
<script crossorigin src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script>
js
class component extends react.component {
componentdidmount() {
greuler({
target: '#chart',
width: 480,
height: 500,
data: {
nodes: [
{id: 0, label: "e1def3", r: 25},
{id: 1, label: "e1p4", r: 15},
{id: 2, label: "e1p2", r: 15},
{id: 3, label: "e1p1", r: 15},
{id: 4, label: "e1p5", r: 15},
{id: 5, label: "e1p6", r: 25}
],
links: [
{source: 0, target: 1, directed: true},
{source: 0, target: 2, directed: true},
{source: 0, target: 3, directed: true},
{source: 1, target: 4, directed: true},
{source: 2, target: 5, directed: true},
{source: 3, target: 4, directed: true},
{source: 4, target: 5, directed: true}
]
}
}).update()
}
render() {
return (
<div id="chart"></div>
);
}
}
reactdom.render(<component />, document.queryselector('#root'));
console.log(react)
score:1
try this:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>navigating spinoza</title>
</head>
<body>
<div id="root"></div>
<div class="row" id="demo"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.js">
</script>
<script src="http://marvl.infotech.monash.edu/webcola/cola.v3.min.js">
</script>
<script src="http://maurizzzio.github.io/greuler/greuler.min.js"></script>
<script>
import react from 'react'
import { render } from 'react-dom'
var instance = greuler({
target: '#demo',
width: 480,
height: 500,
data: {
nodes: [
{id: 0, label: "e1def3", r: 25},
{id: 1, label: "e1p4", r: 15},
{id: 2, label: "e1p2", r: 15},
{id: 3, label: "e1p1", r: 15},
{id: 4, label: "e1p5", r: 15},
{id: 5, label: "e1p6", r: 25}
],
links: [
{source: 0, target: 1, directed: true},
{source: 0, target: 2, directed: true},
{source: 0, target: 3, directed: true},
{source: 1, target: 4, directed: true},
{source: 2, target: 5, directed: true},
{source: 3, target: 4, directed: true},
{source: 4, target: 5, directed: true}
]
}
}).update()
render(
<instance />,
document.getelementbyid('root')
)
</script>
</body>
</html>
Source: stackoverflow.com
Related Query
- how to use a CDN inside a React component
- How can one use a polymer component inside a react component ? Is it possible?
- How to use React Context inside function of Class component
- How can I use React Router's withRouter HOC inside my own higher order component (HOC)?
- How to use a React component inside a Gatsby plugin?
- Refactoring React Class component to Functional, how to use action creator inside useEffect()
- How to use React Router Link component inside an Ant Design Tab component
- How to use Facebook Javascript SDK to login and force re-authentication with React Web and Typescript inside of a component
- How to use <webview> methods inside a react component
- How to use Switch case in React js functional component inside return efficiently by reusing?
- How to use useState inside a react functional component which is async
- How to use AND and OR statement inside the component while comparing in react component
- How can i use a jquery/html/css component inside my react page
- How to use data of an Async function inside a functional component to render HTML in React
- How to use switch statement inside a React component?
- How to use children with React Stateless Functional Component in TypeScript?
- How to use an array as option for react select component
- Making an HTML string from a React component in background, how to use the string by dangerouslySetInnerHTML in another React component
- How to pass props to component inside a React Navigation navigator?
- Unable to use Arrow functions inside React component class
- How to mock a custom hook inside of a React component you want to test?
- how to load React app / Lib inside ExtJs Component
- How to use material-ui IconMenu inside cell of React fixed-data-table
- How to use FormattedMessage inside an option tag in React 0.14?
- How to use Media Queries inside a React Styled Components Keyframe?
- how to import HTML file into React component and use it as a component?
- How do I use React hooks in my component library?
- How to use jest.spyOn with React function component using Typescript
- React Typescript how send props and use it in child component
- How do you correctly use React.lazy() in Typescript to import a react component with a generic type parameter?
More Query from same tag
- How to update react context between components?
- Put title on 2 lines when screen gets too small
- Unable To Deploy React App
- How can I fetch data with useEffect in react
- Is there a way to set the first element in this .map method to a default class on load?
- React useRef from querySelectorAll
- Codemirror lint feature not working react-codemirror in React/Redux/Typescript App
- FormData is empty in parent when passed from child component
- MaterialUI Appbar with Tabs - can it be scrollable AND fullwidth
- Redux using combineReducers returning blank page
- get variables through their name in react
- why blogs are not showing as a list?
- run my method when redux change store props. ReactJS
- Reactjs Static and Dynamic Routes
- ReactJS App: Is it possible to order the rendering of specific divs?
- Unable to import icons from @mui/icons-material
- State updates may be asynchronous, what is exactly this.props?
- Add select all checkbox for mui-datatables data as object( custom columns)
- Split array value using reactjs
- REACT JS - Firestore: How to check documents to validate existing documents and avoid duplicate documents
- Auth0 does not persist login on page refresh for email/password
- How to use useEffect correctly to apply modifications to the array state using Firestore?
- How to add ReactJS to existing node.js backend app
- How to do Nested If statements in ReactJs?
- render a component after some time with setTimeout ( ReactJs)
- How to allow user to save inputs for further review
- Dynamically change redux-form based on field values
- Use object included from global <script> tag inside React component
- How to use state to update the value of variable in the button value property?
- Type error on React Route component