oneto018 / react-dom-box2d Goto Github PK
View Code? Open in Web Editor NEWWrap react dom elements with Box2d physics engine
Wrap react dom elements with Box2d physics engine
Can't get this to work with React v18. Page just spits this:
ERROR
Cannot read properties of undefined (reading 'props')
TypeError: Cannot read properties of undefined (reading 'props')
at e.value (http://localhost:3000/static/js/bundle.js:17275:37)
at finishClassComponent (http://localhost:3000/static/js/bundle.js:36183:35)
at updateClassComponent (http://localhost:3000/static/js/bundle.js:36140:28)
at beginWork (http://localhost:3000/static/js/bundle.js:37766:20)
at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:22757:18)
at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:22801:20)
at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:22858:35)
at beginWork$1 (http://localhost:3000/static/js/bundle.js:42732:11)
at performUnitOfWork (http://localhost:3000/static/js/bundle.js:41979:16)
at workLoopSync (http://localhost:3000/static/js/bundle.js:41902:9)
hi, i cannot get a simlpe demo running with react17 and react-dom 17.
Unhandled Runtime Error
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
Call Stack
resolveDispatcher
node_modules/react-dom-box2d/node_modules/react/cjs/react.development.js (1465:0)
useEffect
node_modules/react-dom-box2d/node_modules/react/cjs/react.development.js (1508:0)
z
node_modules/react-dom-box2d/build/index.js (1:342523)
When I tried the following code:
import React from 'react'
import { World, Item } from 'react-dom-box2d'
import '/styles/langs.css'
// ...
return (
<World gravity={[0, 9.8]}>
{codes.map((code, i) => (
<Item restitution={0.8} key={i}>
<figure>
<div className="picDesc">
<figcaption>
<h3 onClick={() => open(code.html_url)}>
{code.fork && <span>[Fork]</span>} {code.name} ⭐ {code.stargazers_count}
</h3>
<span>
Language: <span className={'lang ' + code.language}>{code.language}</span>
</span>
</figcaption>
{code.description}
</div>
</figure>
</Item>
))}
</World>
)
// ...
it threw an error that I didn't import regeneratorRuntime but it isn't listed in required packages of this component. So please add it to package.json or fix in another way because I have to install and import that dependency manually and this is not cool.
This would be a cool feature because most of the js physics libraries have it.
Maybe we could have a special prop, e.g. dnd={true}
for both World
in case we want to make every element draggable, and for Item
, if we only want item to be dragged.
Example proposal:
<World gravity={[0, 9.8]} dnd>
<Item dnd />
</World>
I made a fork and I'll try to implement this feature using ClientX and ClientY and then submit a PR
Is mouse interaction supported in this library?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.