我已经在我的演示应用程序中实现了一个无限滚动的列表。单击任何行它将转到detail screen
。它工作正常。
**我面临着关注最后选定行的问题**换句话说
运行应用程序。加载第一个20
项目。滚动到底部以加载更多 20 个项目。
然后单击任何项目让说33
rd row 。它将显示33
在详细信息页面中。
现在单击back
它显示焦点的按钮0
或第一行。我想将焦点移动到33
行。或者将滚动位置移动到33
位置。
我使用useContext
api 来存储items
(所有行/数据直到最后一次滚动)和selected item
(选定的索引)。
这是我的代码 https://codesandbox.io/s/dank-cdn-2osdg?file=/src/useInfinitescroll.js
import React from "react";
import { withRouter } from "react-router-dom";
import { useListState } from "./context";
function Detail({ location, history }) {
const state = useListState();
console.log(state);
return (
<div className="App">
<button
onClick={() => {
history.replace({
pathname: "/"
});
}}
>
back
</button>
<h2>{location.state.key}</h2>
<h1>detaiils</h1>
</div>
);
}
export default withRouter(Detail);
any update?
偶然的你
RISEBY
相关分类