Created
March 4, 2020 12:03
-
-
Save jimmychu0807/349b80ffc55c984e015d366bfa9ea2a1 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