mirror of
https://github.com/mmalmi/mmalmi.github.io.git
synced 2025-06-05 17:02:03 +00:00
.
This commit is contained in:
parent
30b45d5f7c
commit
ab0f6998ca
@ -13,22 +13,22 @@ Fed up with writing a ton of Redux boilerplate just to make a form input editabl
|
|||||||
There’s a better alternative: Gun.js. It makes state synchronization and persistence super easy:
|
There’s a better alternative: Gun.js. It makes state synchronization and persistence super easy:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Initialize Gun with options to make sure that the state is synced only locally
|
// Initialize Gun with options that make sure the state is synced to localStorage only
|
||||||
const State = new Gun({multicast: false, peers: [], localStorage: true, file: ‘State.local’});
|
const State = new Gun({multicast: false, peers: [], localStorage: true, file: 'State.local'});
|
||||||
|
|
||||||
class CommentForm {
|
class CommentForm {
|
||||||
componentDidMount {
|
componentDidMount {
|
||||||
State.get(‘comment’).on(comment => this.setState({comment}));
|
State.get('comment').on(comment => this.setState({comment}));
|
||||||
}
|
}
|
||||||
|
|
||||||
onInput(e) {
|
onInput(e) {
|
||||||
State.get(‘comment’).put(e.target.value);
|
State.get('comment').put(e.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return {
|
return {
|
||||||
<form>
|
<form>
|
||||||
<input type=”text” value={{this.state.comment}} onInput={e => this.onInput(e)} />
|
<input type="text" value={{this.state.comment}} onInput={e => this.onInput(e)} />
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user