[Native] Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.
See original GitHub issueVersion
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
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:11 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
@dmueller39 no worries 😃 hope you’re happy with the change