Level 122
try cache busting
1 like
// zustand store method
appInit: async () => {
var network = await appInitialize();
console.log(" network ", network); // default value even after change fired
set((state) => {
state.network = network; // default value even after change fired
});
},
--------------------------------------------------
// my helper function
export const appInitialize = async () => {
var network: null | string = 'default value';
const { ethereum } = window;
try {
if (!ethereum) return alert("please install metamask wallet plugin");
await ethereum?.on("chainChanged", (chainId: any) => {
console.log('network changed ') // event detected
console.log("chainId ", chainId); //// value is sync and always print new value after change 100%
network = chainId; // set the value
console.log("network ", network); // value is sync and always print new value after change 100%
});
return network; // (THE PROBLEM HERE NOT CHANGED YET )
} catch (err) {
alert("somethign want wrong in wallet connection");
}
};
// in page.tsx client component
useEffect(() => {
appInit()
}, []);
Please or to participate in this conversation.