react-native-swipe-list-view icon indicating copy to clipboard operation
react-native-swipe-list-view copied to clipboard

Warning: Function components cannot be given refs.

Open sulaigor opened this issue 4 years ago • 6 comments

I use SwipeListView and get this error message: Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

I am rendering a function component in row and this message receive only if my row isn't swipeable (or if renderHiddenItem return null).

From my perspective it happens because of row 179 of components/SwipeListView.js module of this repo.

I am able to fix this only if I return some component from renderHiddenItem instead of null for current row. But this enabled swipe gesture at the same time...

  • iOS and Android platform
  • RNSLV Version: 3.2.6
  • RN Version: 0.63.4

sulaigor avatar Feb 12 '21 13:02 sulaigor

same issue, same reason

tmirun avatar May 03 '21 11:05 tmirun

For me as well.

SplinterStan avatar Jun 29 '21 13:06 SplinterStan

@sulaigor (and everyone) sorry this completely fell off my radar! I'm trying to address this but I don't see the error message. Can someone please post a reproducible example and I'll get on a fix. Thanks!

jemise111 avatar Sep 06 '21 19:09 jemise111

I am getting this error when I give the swipe-list a ref so that I can use scrollToIndex for scroll to top I'm not sure how to fix it. The solutions I see involve refs for functional components like this

`` const FuncComponent = ({ forwardRef }) => { const [text, setText] = useState('functional component');

forwardRef((text) => renderText(text));

function renderText(text) { setText(text); }

return (

this is {text}
) } ``

But I simply want to be able to do

<SwipeListView ref={listRef} />

The-Pr0grammer avatar Sep 06 '21 20:09 The-Pr0grammer

Hi @The-Pr0grammer I think you're looking for the prop listViewRef, see more here https://github.com/jemise111/react-native-swipe-list-view/blob/master/docs/SwipeListView.md

jemise111 avatar Sep 07 '21 02:09 jemise111

Hi @The-Pr0grammer I think you're looking for the prop listViewRef, see more here https://github.com/jemise111/react-native-swipe-list-view/blob/master/docs/SwipeListView.md

ofc thank you

The-Pr0grammer avatar Sep 07 '21 02:09 The-Pr0grammer