Created
March 4, 2020 12:06
-
-
Save jimmychu0807/f91e774c09f30e26c8ef37bb2bcab8fd to your computer and use it in GitHub Desktop.
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
let unsubscribe; | |
api.query.templateModule.something(newValue => { | |
// The storage value is an Option<u32> | |
// So we have to check whether it is None first | |
// There is also unwrapOr | |
if (newValue.isNone) { | |
setCurrentValue('<None>'); | |
} else { | |
setCurrentValue(newValue.unwrap().toNumber()); | |
} | |
}).then(unsub => { | |
unsubscribe = unsub; | |
}) | |
.catch(console.error); | |
return () => unsubscribe && unsubscribe(); | |
}, [api.query.templateModule]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment