npm i antd@4 styled-components @ant-design/icons
import { Menu } from "antd";
const AppLayout = ({ children }) => {
return (
<div>
<Menu mode="horizontal">
<Menu.Item>
<Link href="/">
<a>노드버드</a>
</Link>
</Menu.Item>
<Menu.Item>
<Link href="/profile">
<a>프로필</a>
</Link>
</Menu.Item>
<Menu.Item>
<Link href="/signup">
<a>회원가입</a>
</Link>
</Menu.Item>
</Menu>
{children}
</div>
);
};
import PropTypes from "prop-types";
// antd@4버젼에 해당
import "antd/dist/antd/css";
const App = ({ Component }) => {
return <Component />;
};
App.propTypes = {
Component: PropTypes.elementType.isRequired,
};
export default App;
import Head from "next/head";
<Head>
<meta charSet="utf-8" />
<title>NodeBird</title>
</Head>
// n/24라고 생각하면 됨.
// 한 줄에 같이 나오게 하려면 합계가 24가 되게 하면 됨
<Row gutter={8}>
<Col xs={24} md={6} />
</Row>
const onChangeId = useCallback((e) => {
setId(e.target.value);
}, []);
<Input name="user-id" value={id} onChange={onChangeId} required />
태그에 style을 줄 때 객체로 넣으면 안됨. 객체비교는 항상 false이므로 항상 리렌더링이 일어나게 됨!
(성능에 큰 영향이 없다면 그냥 인라인으로 써도 무방함)
{} === {} // false
// 아래의 구문이 항상 리렌더링이 일어나게 됨!
<div style={{ marginTop: 10 }}>
// styled-components를 쓰는 것도 하나의 방법임
const ButtonWrapper = styled.div`
margintop: 18px;
`;
<ButtonWrapper>
...
// antd + 인라인 스타일 적용
<Input.Search enterButton style={{ verticalAlign: "middle" }} />
// styled-components 적용 후
const SearchInput = styled(Input.Search)`
vertical-align: middle;
`;
<SearchInput enterButton />
const style = useMemo(() => ({ marginTop: 10 }), []);
<ButtonWrapper style={style} />
<Card
actions={[
<div key="twit">짹짹<br />0</div>,
<div key="followings">팔로잉<br />0</div>,
<div key="followers">팔로워<br />0</div>,
]}
>
<AppLayout>
<NicknameEditForm />
<FollowList header='팔로잉 목록' />
<FollowList header='팔로워 목록' />
...
// LoginForm.js
const [id, setId] = useState("");
const onChangeId = useCallback((e) => {
setId(e.target.value);
}, []);
이러한 코드를
// useInput.js
import { useState, useCallback } from "react";
export default (initialValue = null) => {
const [value, setValue] = useState(initialValue);
const handler = useCallback((e) => {
setValue(e.target.value);
}, []);
return [value, handler];
};
// LoginForm.js
import useInput from "../hooks/useInput";
const [id, onChangeId] = useInput("");
이렇게 줄일 수 있다!