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
7633ae4e39
commit
b58681bdac
@ -19,25 +19,30 @@ const State = new Gun({
|
|||||||
file: 'State.local',
|
file: 'State.local',
|
||||||
multicast: false,
|
multicast: false,
|
||||||
peers: []
|
peers: []
|
||||||
});
|
}).get('state');
|
||||||
|
|
||||||
class CommentForm {
|
class CommentForm extends React.Component {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.state = {comment:''};
|
||||||
|
}
|
||||||
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 class="box">
|
||||||
<input type="text" value={{this.state.comment}} onInput={e => this.onInput(e)} />
|
<input placeholder="Type something" type="text" value={this.state.comment} onChange={e => this.onInput(e)} />
|
||||||
</form>
|
</form>
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you have a comment form that automatically persists its content.
|
Now you have a comment form that syncs its content across component instances and persists it in localStorage.
|
||||||
|
|
||||||
|
See the working example on [Codepen](https://codepen.io/mmalmi/pen/VwWVdKG).
|
Loading…
x
Reference in New Issue
Block a user