January 04, 2020
const checkMail = mail => {
const mailtest = /^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$/i;
return mailtest.test(mail);
};
handleChange = e => {
const { value } = e.target;
this.setState({
[e.target.name]: value
});
};
handleToggle = number => {
const copy = Object.assign({}, this.state.timeState)
const Arr = []
copy[number] = !copy[number]
this.setState(
{
timeState: copy,
},
() => {
for (let click in this.state.timeState) {
if (this.state.timeState[click] === false) {
Arr.push(click)
}
}
this.setState(
{
click: Arr,
},
() => {
this.props.toRender(this.state.click)
}
)
}
)
}
handleMoveBtn = value => {
this.setState({
currentPage: value,
})
}
onClick={() => {
if (currentPage < Math.ceil(comment.length / postPerpage)) {
handleMoveBtn(currentPage + 1);
}
}}
import React from 'react'
import '../QnAList/QnAList.scss'
const PageMove = ({ postPerPage, totalPosts, movePage, currentPage }) => {
const pageNumbers = []
for (let i = 1; i <= Math.ceil(totalPosts / postPerPage); i++) {
pageNumbers.push(i)
}
return pageNumbers.map(number => (
<span
className={number === { currentPage }.currentPage ? 'currentSpan' : ''}
onClick={() => movePage(number)}
key={number}
>
{number}
</span>
))
}
export default PageMove
const handleReply = () => {
if (hostReply !== undefined) {
return (
<div className="host_reply">
<p className="host_head">호스트의 답글</p>
<p className="host_review">{hostReply}</p>
<p className="host_time">{hostTime}</p>
</div>
);
} else {
return null;
}
};
return (
<div className="user_comment">
<div className="user_context">
<img src={userImg} alt="." />
<p className="user_name">{userName}</p>
<p className="user_qus">{userQus}</p>
<div className="comment_time">
<p>{userTime}</p>
<div>
<span>수정 |</span>
<span className="delete_btn" onClick={onClick}>
삭제
</span>
</div>
</div>
</div>
{handleReply()}
</div>
const fetchData = (...req) =>
fetch(...req)
.then(res => res.json())
.catch(err => {
throw err
})
export default fetchData
componentDidMount() {
fetchData("http://localhost:3000/data/data.json").then(res => {
this.setState({
spaceData: res.spaceData,
topTag: res.spaceData.topTag,
reserveList: res.spaceData.spaceInfo,
reserveWarning: res.spaceData.reserveWarning
});
});