menu
Channels
Team

Using useContext hook within <Canvas>

October 14, 2019 at 6:35pm

Using useContext hook within <Canvas>

October 14, 2019 at 6:35pm (Edited 1 year ago)
When doing this, the application fails. Example here:
The workaround is to consume the context ouside of Canvas, then pass props down to child elements. Is that pretty much the pattern here? Took me a while to figure out what was going on and could be a possible footgun for other users of the library.
I was going to post a issue to github for this, but figure I might want to ask here first.

October 14, 2019 at 8:07pm
its a react issue unfortunately. any reconciler is victim to it, react cant share context among multiple context objects. the react team is trying to figure it out, but nothing concrete yet.
Edited
  • reply
  • like

October 15, 2019 at 3:52pm
Gotcha. Good to know. Thanks! I've been enjoying the library so far, so thanks for the hard work on it :)
Edited
  • reply
  • like

March 29, 2020 at 1:12am
Has there been any traction on this? It is a fairly large issue for me as my primary method of transferring data around is Context.
  • reply
  • like
Nvm, I did some more searching. For anyone else discovering this issue, a solution was provided in another thread.
The suggestion was to create a new Provider within the <Canvas /> and use that to forward the previous Context. It's a little clunky imo, but it is a good enough stopgap for now.

Redux integration

thumbsup
0
message-simple
6
  • reply
  • like

March 29, 2020 at 8:01am
It's the only possible solution to this and sadly the issue affects all reconcilers, there's really nothing we can do other than asking the react team to fix it
  • reply
  • like