rewrite component to be functional
This commit is contained in:
parent
37727bfd3d
commit
3c9c46da18
1 changed files with 17 additions and 32 deletions
|
@ -16,47 +16,32 @@
|
||||||
|
|
||||||
import './main.scss';
|
import './main.scss';
|
||||||
import ReactDom from 'react-dom';
|
import ReactDom from 'react-dom';
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { encrypt_string } from '../pkg';
|
import { encrypt_string } from '../pkg';
|
||||||
|
|
||||||
const hljs = require('highlight.js');
|
import hljs from 'highlight.js'
|
||||||
(window as any).hljs = hljs;
|
(window as any).hljs = hljs;
|
||||||
require('highlightjs-line-numbers.js');
|
require('highlightjs-line-numbers.js');
|
||||||
|
|
||||||
class PasteForm extends React.Component {
|
const PasteForm = () => {
|
||||||
constructor(props) {
|
const [value, setValue] = useState("");
|
||||||
super(props)
|
|
||||||
this.state = {
|
|
||||||
value: "Sample text"
|
|
||||||
};
|
|
||||||
this.handleChange = this.handleChange.bind(this);
|
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChange(event) {
|
|
||||||
this.setState({value: event.target.value});
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit(event) {
|
|
||||||
try {
|
|
||||||
encrypt_string(this.state.value);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
encrypt_string(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
return (
|
||||||
<pre className='paste'>
|
<pre className='paste'>
|
||||||
<form class="hljs centered" onSubmit={this.handleSubmit}>
|
<form className='hljs centered' onSubmit={handleSubmit}>
|
||||||
<textarea value={this.state.value} onChange={this.handleChange} />
|
<textarea
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => setValue(e.target.value)}
|
||||||
|
/>
|
||||||
<input type="submit" value="submit" />
|
<input type="submit" value="submit" />
|
||||||
</form>
|
</form>
|
||||||
</pre>
|
</pre>
|
||||||
);
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createUploadUi() {
|
function createUploadUi() {
|
||||||
|
|
Loading…
Reference in a new issue