Skip to content

Instantly share code, notes, and snippets.

@YounglanHong
Last active June 11, 2020 06:54
Show Gist options
  • Save YounglanHong/f499350daf924bd99374ea199c259c29 to your computer and use it in GitHub Desktop.
Save YounglanHong/f499350daf924bd99374ea199c259c29 to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from 'react';
import { withRouter } from 'react-router-dom';
import axios from 'axios';
import Button from '@material-ui/core/Button';
axios.defaults.withCredentials = true;
// GetMsg
// 2. history 객체를 props로 받습니다.
function GetMsg({ history }) {
const [text, setText] = useState('');
const [date, setDate] = useState('');
useEffect(() => {
axios({
method: 'get',
url: 'http://15.164.164.204:4000/message/getMessage',
}).then(res => {
setText(res.data.data.inputText);
setDate(res.data.data.createdAt);
});
}, []);
return (
<div>
// 생략
<Button
color="primary"
type="submit"
fullWidth
value="응원메세지 작성하러 가기"
style={{ fontSize: '17px' }}
// 3. sendMsg 컴포넌트로 이동하는 onClick 이벤트를 생성합니다.
onClick={() => history.push('/sendmsg')}
>
응원메세지 작성하러 가기
</Button>
</div>
);
}
// 1. withRouter 고차함수로 GetMsg 컴포넌트를 감싸줍니다.
export default withRouter(GetMsg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment