Reactjs 如何根据本地存储的状态更新组件?
我有两页 localhost:3000和1。localhost:3000,在执行一些操作后,我重定向并将一些数据从localhost:3000传输到1。localhost:3000,我在第二个页面上获取此数据,但仅在更新后,第一次重定向时如何获取此数据?不必刷新第二页?(数据在本地存储中)Reactjs 如何根据本地存储的状态更新组件?,reactjs,Reactjs,我有两页 localhost:3000和1。localhost:3000,在执行一些操作后,我重定向并将一些数据从localhost:3000传输到1。localhost:3000,我在第二个页面上获取此数据,但仅在更新后,第一次重定向时如何获取此数据?不必刷新第二页?(数据在本地存储中) // It works, but only after the update componentDidMount() { const interval = setInterval(()
// It works, but only after the update
componentDidMount() {
const interval = setInterval(() => {
if (localStorage.getItem('urlParams') !== null) {
clearInterval(interval)
const res = JSON.parse(localStorage.getItem('urlParams'))
const newToken = decodeURI(res.params.token)
localStorage.setItem('accessToken', newToken)
}
}, 500)
}