* Update dependencies * Update examples with simplified storage * Update dependencies * Revert tsc location override (check) * Update dependencies
43 lines
1.2 KiB
Markdown
43 lines
1.2 KiB
Markdown
# storage via API (part II)
|
|
|
|
[Previously](tut-002.md) we queried intentions via HOC, then [followed up](tut-003.md) with querying via API. Here we will replace our previous HOC component with the same storage queries.
|
|
|
|
# the component
|
|
|
|
Here we extend the component from the previous section, adding a subscription to intentions to create our [new component](../packages/app-example/src/comp-004.tsx) -
|
|
|
|
```js
|
|
class Comp extends React.PureComponent<ApiProps, State> {
|
|
...
|
|
componentDidMount () {
|
|
this.setState({
|
|
subscriptions: [
|
|
this.subscribeIntentions(),
|
|
this.subscribeProposals()
|
|
]
|
|
});
|
|
}
|
|
|
|
subscribeIntentions () {
|
|
const { api } = this.props;
|
|
|
|
return api.state
|
|
.getStorage(storage.staking.public.intentions)
|
|
.subscribe((intentions: StorageIntentions) => {
|
|
this.setState({
|
|
intentions: intentions.map(encodeAddress)
|
|
});
|
|
});
|
|
}
|
|
...
|
|
}
|
|
```
|
|
|
|
# walk-through
|
|
|
|
This subscription is much simpler than what was found before, however it follows the same basic approach - query, transform the result.
|
|
|
|
# next steps
|
|
|
|
[Next up](tut-005.md), we will be using the actual data we have collected to render something useful on-screen.
|