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.

[Native] Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.

See original GitHub issue

Version

styled-components: 1.4.6 react-native: 0.44.0

Reproduction

This issue was reported already in #674 but it was considered fix there.
I used this repo to have a simple example:
https://github.com/dbertella/RNstyledPlayground

Steps to reproduce

Declaring a functional component ex:

// Container.js
export default (props) => <View {...props} />

Compose a styled-components with it ex

//index.ios.js
import Container from './Container';
...
const ContainerWithBorder = styled(Container)`
  borderBottomWidth: 1
`;

...
  render() {
    return (
      <ContainerWithBorder>
        <Text>This is my container</Text>
      </ContainerWithBorder>
    );
  }

Expected Behavior

I’m not using ref or innerRef anywhere, I’m not expecting this warning

Actual Behavior

It seems to happen when you have the js debugger active.
Stack trace:

Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.

Check the render method of `Styled(undefined)`.
    in Unknown (created by Styled(undefined))
    in Styled(undefined) (created by RNstyledComponent)
    in RNstyledComponent
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer

screen shot 2017-05-04 at 11 35 09

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kittencommented, May 4, 2017

This seems to only be affecting v1.x: https://github.com/styled-components/styled-components/blob/master/src/models/StyledNativeComponent.js#L117

It should be fixed in v2, but we need to make sure not to break it in #764

I’m not sure whether it’s worth it to still fix it for v1

0reactions
kittencommented, May 26, 2017

@dmueller39 no worries 😃 hope you’re happy with the change

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does "Stateless function components cannot be given ...
Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail. Check the render method of DragSource( ...
Read more >
Solved: Function components cannot be given refs ... - GitHub
It will not generate an error of Function components cannot be given refs. ... cannot be given refs. Attempts to access this ref...
Read more >
next link function components cannot be given refs. attempts ...
Bug report Describe the bug Using a functional component as a child of <Link/> causes: Warning: Function components cannot be given refs. Attempts...
Read more >
What does "Stateless function components cannot be given ...
React Redux 3 attaches a ref to the component you give it regardless of whether or not it's stateless. The warning you see...
Read more >
ref prop should not be used on React function components
See · React Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?....
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