react-activation
react-activation copied to clipboard
KeepAlive中的自定义属性更新无法触发cachingNodes更新
function AliveItem(props) {
const id = props.match.params.id
const [query, setQuery] = useState()
const shared = id % 2 === 0
// 双数共享同一份缓存
// 单数独享缓存
return (
<>
<button onClick={() => setQuery('?name=test')}>Set Query</button>
<KeepAlive
query={query || '?name=demo'}
name={shared ? 'ItemShared' : `Item${id}`}
id={shared ? undefined : id}
>
<Item {...props} />
</KeepAlive>
</>
)
}
如上代码所示,希望在更新query字段时,可以触发cachingNodes更新
复现示例:https://codesandbox.io/s/ke-guan-bi-de-yi-fang-wen-lu-you-tab-shi-li-ke-an-lu-you-can-shu-fen-duo-fen-huan-cun-forked-9o0w0b?file=/src/App.js