Skip to content
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

BUG: refs cannot be applied because of stateless functions. #20

Open
3rd-Eden opened this issue Jan 9, 2018 · 2 comments
Open

BUG: refs cannot be applied because of stateless functions. #20

3rd-Eden opened this issue Jan 9, 2018 · 2 comments
Labels

Comments

@3rd-Eden
Copy link
Contributor

3rd-Eden commented Jan 9, 2018

Problem:

You can use ref's with stateless functions. This means that non of the svgs components can have a ref assigned to them.

Solution:

Change all stateless functions to class's.

@3rd-Eden 3rd-Eden added the bug label Jan 9, 2018
@dennishansen
Copy link

dennishansen commented Aug 1, 2019

Or a solution is to use forwardRef.

@3rd-Eden
Copy link
Contributor Author

Yes/No/Maybe

The reason why I don't like that approach is the additional wrapping that you have per component. When you're rending a forwardRef your render tree will actually be:

<ForwardedRef>
  <Svg>
    <ForwardedRef>
      <G>
        <ForwardedRef>
          <Square />
        <ForwardedRef>
      </G>
    </ForwardedRef>
  </Svg>
</ForwardedRef>

vs

<Svg>
  <G>
    <Square />
  </G>
</Svg>

This might not seem like a big problem, which is true for when you have a single element you're working with. With an SVG asset it's not uncommon to have a deeply nested structure of paths, groups, and other shapes and when you need to debug one of those elements this is going to add up. In addition to that, it's more painful to write tests against due to this additional wrapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants