I have this "drop menu" that literally drops from the top using the Matter.js 2d physics engine: https://github.com/NeilSentence/galerie-sens
let world, engine, runner
const { Engine, Runner, World, Bodies, MouseConstraint, Composites, Body } = Matter
class Scene extends React.Component {
constructor(props){
super(props)
this.state = {
removeNonMenuBlocks: this.props.switchsections
}
}
componentDidMount(){
const runCode = () => {
// set up all matter.js stuff here (works!).
// At the bottom, an IIFE called update:
(function update(removeNonMenuBlocks){
requestAnimationFrame(update)
// updates CSS positions of DOM elements. works(!)
// but I need access to the class props here, to dynamically remove
// objects from world in real-time, as I do when HTML classes change
// such as when "delayed-fallable" class is added
console.log(removeNonMenuBlocks)
// just prints an ever-increasing number
Engine.update(engine)
})(this.state.removeNonMenuBlocks)
}
run()
}
}
My intuition is that the ever-increasing number is a good thing because it means something actually updates. But how to get to the juicy state?
The place where the Scene component is used has "parent state" and passes it in via a prop (bool)
switchsections={()=>{return this.state.switchsections}}
Full project is under src/components/menudrop.js