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
Getting Invalid warnings when creating own ref #324
Comments
Please read the docs. The This is what the warning message is talking about. Fix this first, then if things are still broken- we can talk more. |
This is what I based the idea off of.. When I use the ref provided from the infiniteLoader I get the following error For my component to work I need to call to the ref and reset the scroll when the input is emptied. By replacing Here is the code that I changed ...
export class SearchFieldInfiniteScrollComponent extends BaseComponent {
listRef;
scrollToTop() {
this.listRef.current.scrollToItem({ align: 'start' });
}
render() {
...
<InfiniteLoader
isItemLoaded={isRowLoaded}
loadMoreItems={loadMoreRows}
itemCount={loadedRowCount}
threshold={threshold}
>
{({ onItemsRendered, ref }) => {
this.listRef = ref;
return (
<List
ref={ref}
height={listHeight}
onItemsRendered={onItemsRendered}
itemCount={loadedRowCount}
itemSize={rowHeight}
width={dropdownWidth}
> |
I should mention that when I try to access the scrollToItem method with the inner ref within the List component I still get the above error |
you should understand which ref is for which component, try |
{({ onItemsRendered, ref }) => (
<List
ref={list => {
ref(list); // Give InfiniteLoader a reference to the list
this.listRef.current = ref; // Set your own ref to it as well.
}}
/>
)} I'm going to close this issue, since I'm pretty sure it's been been answered now. If you are still running into any additional problems, it would probably be best provide a complete runnable repro in Code Sandbox. :) |
My case: InfntLdrHOC.tsx import InfiniteLoader from 'react-window-infinite-loader';
...
<InfiniteLoader
isItemLoaded={isItemLoaded}
loadMoreItems={onScroll}
itemCount={listCount}
>
{({ onItemsRendered, ref }) => {
return (
<ListOfMessages
config={{
messages,
height,
width,
ref,
onItemsRendered,
isFetchingNewScenario,
}}
/>
);
}}
</InfiniteLoader> ListOfMessages.tsx import React from 'react';
import { VariableSizeList as List } from 'react-window';
import Message from '../Message';
class ListOfMessagesClass extends React.Component<any> {
private listRef = React.createRef<any>();
componentDidUpdate(prevProps: any) {
const {
isFetchingNewScenario: isFetchingNewScenarioPrev,
} = prevProps.config;
// eslint-disable-next-line react/destructuring-assignment
const { isFetchingNewScenario } = this.props.config;
if (isFetchingNewScenarioPrev && !isFetchingNewScenario) {
this.scrollToNewMessage();
}
}
scrollToNewMessage = () => {
this.listRef.current!.scrollToItem(0);
};
render() {
const { config } = this.props;
const {
messages = [],
listCount,
height,
width,
ref,
onItemsRendered,
} = config;
const listLength = messages.length;
return (
<>
<List
height={height}
itemCount={listLength}
itemSize={(index: any) => messages[index].messageRenderHeight}
width={width}
ref={list => {
ref(list); // Give InfiniteLoader a reference to the list
// @ts-ignore
this.listRef.current = list; // Set your own ref to it as well.
}}
onItemsRendered={onItemsRendered}
itemData={messages}
outerRef={this.outerRef}
>
{Message}
</List>
</>
);
}
}
export default ListOfMessages; |
Was also stuck on this, got auto-scroll to bottom like this: const [listRef, setListRef] = useState(null)
// Scroll To Bottom
useEffect(() => {
listRef?.scrollToItem?.(data.length - 1)
}, [listRef, data.length])
// ...
<>
// ...
{({ onItemsRendered, ref: setRef }) => {
return (
<FixedSizeList
itemCount={data?.length}
onItemsRendered={onItemsRendered}
ref={(list) => {
// @ts-ignore next-line
setRef?.(list); // Gives the list ref to the parent InfiniteLoader
setListRef(list);
}}
height={height}
width={width}
itemSize={50}
>
{RenderRow}
</FixedSizeList>
);
}}
// ...
</> |
What I Expect
When I am mid scroll, and the user changes the input, the scroll index should jump back to the top of the list once the new data loads.
What is happening
I was able to reset the scroll back to the top, but now I am getting warnings that the
list
ref and theonItemsRendered
is invalid. Even though they are warnings they are hindering the list from populating. I have tested this by taking out thescrollToTop
logic and replacing the List ref with the ref provided byInfiniteLoader
.Am I implementing the new ref incorrectly?
The Code
The text was updated successfully, but these errors were encountered: