Skip to content

Instantly share code, notes, and snippets.

@YounglanHong
Last active June 11, 2020 07:02
Show Gist options
  • Save YounglanHong/c7ed12e6cc9d6d836fec51e605b55c04 to your computer and use it in GitHub Desktop.
Save YounglanHong/c7ed12e6cc9d6d836fec51e605b55c04 to your computer and use it in GitHub Desktop.
import React, { useState } from 'react';
import { withRouter } from 'react-router-dom';
import axios from 'axios';
import Button from '@material-ui/core/Button';
axios.defaults.withCredentials = true;
// SendMsg
//2. history 객체를 props로 받습니다.
function SendMsg({ history }) {
const [value, setValue] = useState('');
const [countText, setCount] = useState(0);
// 3. history의 goBack() 메소드를 이용해 뒤로가기 함수를 작성합니다.
function handleBack() {
history.goBack();
}
return (
<div>
// 생략
<Button
color="primary"
type="submit"
fullWidth
value="뒤로 가기"
style={{ fontSize: '17px' }}
// 4. 뒤로가기 함수를 onClick 이벤트와 연결합니다.
onClick={handleBack}
>
뒤로 가기
</Button>
// 생략
</div>
);
}
// 1. withRouter 고차함수로 SendMsg 컴포넌트를 감싸줍니다.
export default withRouter(SendMsg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment