aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/Post.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-04-08 11:41:11 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:54 +0300
commit38de2a3fa75b50973638417b203368570928e2c5 (patch)
tree17f271694a9b20c65e8a458b36d5f66e1d6733f2 /vnext/src/components/Post.js
parent91c895a7e3a58ea3c3ee69e43cf3db1791d64014 (diff)
Post using hooks
Diffstat (limited to 'vnext/src/components/Post.js')
-rw-r--r--vnext/src/components/Post.js44
1 files changed, 13 insertions, 31 deletions
diff --git a/vnext/src/components/Post.js b/vnext/src/components/Post.js
index 3fdb0361..36c3d837 100644
--- a/vnext/src/components/Post.js
+++ b/vnext/src/components/Post.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { memo, useRef, useState } from 'react';
import ReactRouterPropTypes from 'react-router-prop-types';
import { UserType } from './Types';
@@ -9,17 +9,9 @@ import MessageInput from './MessageInput';
import { post } from '../api';
-export default class Post extends React.Component {
- constructor(props) {
- super(props);
- let params = qs.parse(window.location.search.substring(1));
- this.state = {
- attach: '',
- body: params.body || ''
- };
- this.fileinput = React.createRef();
- }
- postMessage = (template) => {
+function PostComponent(props) {
+ let params = qs.parse(window.location.search.substring(1));
+ let postMessage = (template) => {
const { attach, body } = template;
post(body, attach)
.then(response => {
@@ -29,28 +21,18 @@ export default class Post extends React.Component {
}
}).catch(console.log);
}
- attachChanged = (event) => {
- this.setState({
- attach: event.target.value
- });
- }
- bodyChanged = (event) => {
- this.setState({
- body: event.target.value
- });
- }
- render() {
- return (
- <div className="msg-cont">
- <MessageInput rows="7" text={this.state.body} data={{ mid: 0, timestamp: '0' }} onSend={this.postMessage}>
- *weather It is very cold today!
+ return (
+ <div className="msg-cont">
+ <MessageInput rows="7" text={params.body || ''} data={{ mid: 0, timestamp: '0' }} onSend={postMessage}>
+ *weather It is very cold today!
</MessageInput>
- </div>
- );
- }
+ </div>
+ );
}
-Post.propTypes = {
+export default memo(PostComponent);
+
+PostComponent.propTypes = {
history: ReactRouterPropTypes.history.isRequired,
visitor: UserType
};