Skip to content

Instantly share code, notes, and snippets.

@jimmychu0807
Created March 4, 2020 12:06
Show Gist options
  • Save jimmychu0807/f91e774c09f30e26c8ef37bb2bcab8fd to your computer and use it in GitHub Desktop.
Save jimmychu0807/f91e774c09f30e26c8ef37bb2bcab8fd to your computer and use it in GitHub Desktop.
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
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