Stateless function components cannot be given refs. Attempts to access this ref will fail
See original GitHub issueHello,
I’m having an issue with react-select, when trying to use a custom Option component.
This is what my option component looks like:
import * as React from 'react';
const Option = (props) => {
const handleMouseDown = (event) => {
event.preventDefault();
event.stopPropagation();
props.onSelect(props.option, event);
};
const handleMouseEnter = (event) => {
props.onFocus(props.option, event);
};
const handleMouseMove = (event) => {
if (props.isFocused) return;
props.onFocus(props.option, event);
};
return (
<div className={props.className}
onMouseDown={handleMouseDown}
onMouseEnter={handleMouseEnter}
onMouseMove={handleMouseMove}
title={props.option.title}>
<img src={props.option.thumbnail}/> {props.children}
</div>
);
};
export default Option;
And used on the Select element like optionComponent={Option}
.
However, with this, I’m getting the following error:
index.js:2177 Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.
Check the render method of `Select`.
in Option (created by Select)
in div (created by Select)
in div (created by Select)
in div (created by Select)
Did I miss something?
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6
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
Solved: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? #2120.
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 >warning: function components cannot be given refs. attempts ...
As the warning state you cannot assign refs to functional component without the usage the forwardRef ... given refs. Attempts to access this...
Read more >gpbl/react-day-picker - Gitter
I got this Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.
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
Turns out the solution was to implement the
OptionComponentProps
for the props and convert to a react class.this code work normal