import React, { memo } from 'react'; import ReactRouterPropTypes from 'react-router-prop-types'; import { UserType } from './Types'; import qs from 'qs'; import MessageInput from './MessageInput'; import { post, update } from '../api'; function PostComponent({ location, visitor, history }) { let draftMessage = (location.state || {}).draft || {}; let params = qs.parse(window.location.search.substring(1)); let postMessage = (template) => { const { attach, body } = template; const postAction = draftMessage.mid ? update(draftMessage.mid, 0, body) : post(body, attach); postAction .then(response => { if (response.status === 200) { const msg = response.data.newMessage; history.push(`/${visitor.uname}/${msg.mid}`); } }).catch(console.log); }; return (
*weather It is very cold today!
); } export default memo(PostComponent); PostComponent.propTypes = { location: ReactRouterPropTypes.location, history: ReactRouterPropTypes.history.isRequired, visitor: UserType };