-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
useDidShow取值错误 #4664
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
麻烦请提供一个复现 Demo 可以吗 |
... export default () => { const [number, setState] = useState(0); useDidShow( () => { return ( 不知道你能不能看懂。点击一次增加之后,页面跳转出去再跳回来,这时候理想值应该是打印1.实际上打印的还是0 |
Hello~ 您的问题我们无法复现。如果有空的话还请拔冗提供一个简单的复现 demo,否则这个 issue 将在 15 天后被自动关闭。 如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。 Good luck and happy coding~ |
同样得问题,赶紧解决下,紧急 如: 抽离出来一个存取本地storage hooks const useLocalStorage = <T>(key: string, initialValue?: T, isSerial?: boolean): [T, (value: T) => void] => {
const [state, setState] = useState<T>(() => {
try {
const storageValue = Taro.getStorageSync(key);
if(typeof storageValue !== 'string') {
Taro.setStorageSync(key, isSerial ? String(initialValue) : JSON.stringify(initialValue));
return initialValue;
} else {
return isSerial ? storageValue : JSON.parse(storageValue || 'null');
}
} catch(e) {
console.error('init storage value error')
return initialValue;
}
});
useEffect(() => {
try {
Taro.setStorageSync(key, isSerial ? String(state) : JSON.stringify(state));
} catch(e) {
console.error('set storage value error')
}
}, [state]);
return [state, setState];
};
export default useLocalStorage; 在login page 页设置完token const [token, setToken] = useLocalStorage<string>('token');
function login() {
handleTOken() {
setToken('asdasdasdasd') // 此时设置token
Taro.navigateTo({
url: "/pages/index/index"
})
}
} 但是切换到index page页面获取得时候 const [token] = useLocalStorage<string>('token');
function Index() {
useDidShow() {
console.log(token) // 此时打印token依然是null
}
} |
@wangruiStart 没有复现你所说的问题,麻烦升级到最新版本试试 |
@luckyadam 1.3.19 |
1.3.22正常了@xxyGoTop |
如果用到f2,不要升级。会报错。采坑了。。。。。@ xxyGoTop |
好吧,暂时就不升级了 @wangruiStart |
问题描述
A页面useSelector从store中取到的prop 为false,useState的值也是false,A 页面进行操作将prop和state都改为true。路由跳转到B。再从B跳回A后触发A的useDidShow, 这时候回调中的props和state都是
还是false。是初始值
报错信息
系统信息
补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]
The text was updated successfully, but these errors were encountered: