-
-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
attach multiple refs to canvas element #1290
Conversation
Thanks for looking into this! It seems to me that using |
I was worried that attaching refs like I am doing in this PR was not the "right"/idiomatic way in React so I was trying to figure out another solution, but you are right, |
Here's another food for thought, what happens if we pass |
Codecov Report
@@ Coverage Diff @@
## master #1290 +/- ##
==========================================
- Coverage 33.24% 33.12% -0.13%
==========================================
Files 219 219
Lines 8413 8632 +219
Branches 1841 1938 +97
==========================================
+ Hits 2797 2859 +62
- Misses 5061 5181 +120
- Partials 555 592 +37
Continue to review full report at Codecov.
|
Just did what you recommended! I had to pass |
Great! I'm glad that wasn't too hard and it also cleans up the code. I was just looking at the Here's my train of thought:
One last comment: since |
…and when component mounts (newSegmentCanvas); set default no op for updatePerspective
So turns out that UPDATE: |
So I think this is fine. We've solved the original problem (the refs warning) in a way that keeps our code clean. I'm very pleased with the result. I did a little bit of reflecting on how and when we calculate perspectives, and if #1145 is still an extant bug (I assume it is, but haven't investigated further) then there is a problem that runs a little deeper than the ref issue. In which case we may need to reconsider when it's being called anyway, and I'm happy to deal with later - as it's out of scope for this PR. Merging now! |
Previously we attached a ref directly to the
![image](https://user-images.githubusercontent.com/17012261/57627681-731e7280-7566-11e9-94ae-24711d9485ef.png)
<SegmentCanvas />
component but after updating our dependencies (specifically React), a warning message is now displayed in the console as shown below:After looking into the
<SegmentCanvas />
I noticed that<SegmentCanvas />
also has attached a ref to itscanvas
element. In order to attach two refs to the samecanvas
element, I have forwarded the ref from the<Segment />
component as a prop calledforwardRef
and called a function to attach boththis.props.forwardRef
andthis.canvasEl
to thecanvas
element similar to the solution discussed here.Another option that I am thinking is to only have one ref from the
<Segment />
component be passed into<SegmentCanvas />
and attached to thecanvas
element. Instead of creating a new ref,this.canvasEl
, in<SegmentCanvas />
we could reusethis.props.forwardRef
(or rename it tothis.props.canvasEl
) to do what is needed in<SegmentCanvas />
which is to draw the segment. This way we could use theReact.forwardRef
as shown here?@louh Let me know which way sounds better. I think both of these solutions will remove the warning displayed in console.