question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m using redux to connect child elements in my scene.

This one took a few hours to track down. I have a simple component connected to redux, like:

@connect(state => ({}))
class MyFriend extends Component {
  render() {
    return null;
  }
}

If I render it outside a <Canvas>, it works fine:

      <div>
        <MyFriend />
        <Canvas />
      </div>

However if I render it inside a Canvas:

      <div>
        <Canvas>
          <MyFriend />
        </Canvas>
      </div>

Then the app crashes:

Uncaught Invariant Violation: Could not find “store” in the context of “Connect(MyFriend)”

I suspect it’s related to the custom rendering here, but I’m still digging into it: https://github.com/drcmda/react-three-fiber/blob/master/src/canvas.js#L197-L204

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

24reactions
AndrewRayCodecommented, Mar 25, 2019

This didn’t work either:

Canvas.contextTypes = { store: PropTypes.object };
Canvas.childContextTypes = { store: PropTypes.object };

I’m not sure if this is related to the useEffect() call internally, or the .memo() of the Canvas component?

This works (I think), which should probably give me a clue as to what’s going on. It’s not ideal:

import { ReactReduxContext, Provider } from 'react-redux';

...

        <ReactReduxContext.Consumer>
          {({ store }) => (
            <Canvas>
              <Provider store={store}>
                 ...
              </Provider>
            </Canvas>
         )}
      </ReactReduxContext.Consumer>
9reactions
stephencorwincommented, Nov 12, 2020

@JustFly1984 We rolled out a useContextBridge hook in the @react-three/drei package for official use within the react-three-fiber ecosystem.

function SceneWrapper() {
  // bridge any number of contexts
  const ContextBridge = useContextBridge(ThemeContext, GreetingContext)
  return (
    <Canvas>
      <ContextBridge>
        <Scene />
      </ContextBridge>
    </Canvas>
  )
}

function Scene() {
  // we can now consume a context within the Canvas
  const theme = React.useContext(ThemeContext)
  const greeting = React.useContext(GreetingContext)
  return (
    //...
  )
}

It’s been working out really well and the api is pretty friendly 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating and Destroying a Context
The Context interface contains methods for creating and destroying a subcontext, a context that is bound in another context of the same type....
Read more >
context.destroy() • Waypoints - I Make Web Things
This destroys every waypoint in the context, and consequently unbinds any scroll and resize handlers attached to this context's element.
Read more >
agc context destroy | Amazon Genomics CLI
Destroy contexts in the current project. Synopsis. destroy is for destroying one or more contexts. It destroys AGC resources in AWS. agc context...
Read more >
when an execution context is destroyed ... - DEV Community ‍ ‍
when an execution context is destroyed, it destroys the variable and functions defined inside them. Unless you take into account the concept ...
Read more >
Puppeteer Execution context was destroyed, most likely ...
I am facing this problem in puppeteer in a for loop when i go on another page to get data, then when i...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found