inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[리뉴얼] React로 NodeBird SNS 만들기

리렌더링 이해하기

styled-components 적용 질문

해결된 질문

443

i1004gy

작성한 질문수 36

0

import React from "react";
import PropTypes from "prop-types";
import Link from "next/link";
import { Input, Menu, Row, Col } from "antd";
import { useState, UseMemo } from "react";
import UserProfile from "../components/UserProfile";
import LoginForm from "../components/LoginForm";
import styled from "styled-components";

const { Search } = Input;
const onSearch = (value) => console.log(value);
const SearchInput = styled(Input.Search)`
  verticalalign: middle;
  width: 200px;
  marginleft: 10px;
`;

const items = [
  {
    label: <Link href="/">노드버드</Link>,
    key: "mail",
  },
  {
    label: (
      <div>
        <Link href="/profile">프로필</Link>
        <SearchInput
          placeholder="input search text"
          enterButton="Search"
          onSearch={onSearch}
        />
      </div>
    ),

    key: "profile",
  },
  {
    label: <Link href="/signup">회원가입</Link>,
    key: "signup",
  },
];
let tmp = "mail";
const AppLayout = ({ children }) => {
  const [isLoggedIn, setIsLoggedIn] = useState(false);
  const [current, setCurrent] = useState(tmp);
  console.log(current);
  const onClick = (e) => {
    console.log("click ", e);
    setCurrent(e.key);
    tmp = e.key;
  };
  return (
    <div>
      <Row>
        <Col span={12} offset={6}>
          <Menu
            mode="horizontal"
            onClick={onClick}
            selectedKeys={[current]}
            items={items}
          />
        </Col>
      </Row>

      <Row gutter={8}>
        <Col xs={24} md={6}>
          {isLoggedIn ? <UserProfile /> : <LoginForm />}
        </Col>
        <Col xs={24} md={12}>
          {children}
        </Col>
        <Col xs={24} md={6}>
          <a
            href="https://github.com/seroak"
            target="_blank"
            rel="noreferrer noopener"
          >
            Made by seooak
          </a>
        </Col>
      </Row>
    </div>
  );
};

AppLayout.propTypes = {
  children: PropTypes.node.isRequired,
};

export default AppLayout;

제가 메뉴를 만들 때 ant 디자인 공식문서를 보고 const item에 요소를 작성해서 메뉴를 만드는 방식으로 코드를 작성했는데 이렇게 작서하니까 SearchInput에 styled 컴포넌트를 적용하는 것이 안됩니다 어떤 방식이 좋을까요?

const SearchInput = styled(Input.Search)`
  verticalalign: middle;
  width: 200px;
  marginleft: 10px;
`;

const items = [
  {
    label: <Link href="/">노드버드</Link>,
    key: "mail",
  },
  {
    label: (
      <div>
        <Link href="/profile">프로필</Link>
        <SearchInput
          placeholder="input search text"
          enterButton="Search"
          onSearch={onSearch}
        />
      </div>
    ),

맨위의 코드가 전체 코드이고 제가 궁금한 부분이 있는 코드는 아래에 있습니다

react redux node.js express next.js

답변 2

0

i1004gy

아 그렇네요! 감사합니다 그런데 styled-components를 적용하고 맨 처음 랜더링 된후 좀 시간이 지나고 나서 style이 적용이 되는데 이건 개발 모드여서 생기는 현상인가요? 인라인으로 style을 적으면 바로 style이 적용이 됩니다

0

제로초(조현영)

ssr용 설정 따로 하셔야합니다. 강좌 배포 부분에 나옵니다

0

제로초(조현영)

css는

vertical-align

margin-left

입니다.

넥스트 버젼 질문

0

78

2

로그인시 401 Unauthorized 오류가 뜹니다

0

90

1

무한 스크롤 중 스크롤 튐 현상

0

177

1

특정 페이지 접근을 막고 싶을 때

0

103

2

createGlobalStyle의 위치와 영향범위

0

97

2

인라인 스타일 리렌더링 관련

0

92

2

vsc 에서 npm init 설치시 오류

0

148

2

nextjs 15버전 사용 가능할까요?

0

160

1

화면 새로고침 문의

0

123

1

RTK에서 draft, state 차이가 있나요?

0

155

2

Next 14 사용해도 될까요?

0

452

1

next, node 버전 / 폴더 구조 질문 드립니다.

0

349

1

url 오류 질문있습니다

0

211

1

ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out

0

375

1

sudo certbot --nginx 에러

0

1281

2

Minified React error 콘솔에러 (hydrate)

0

470

1

카카오 공유했을 때 이전에 작성했던 글이 나오는 버그

0

248

1

프론트서버 배포 후 EADDRINUSE에러 발생

0

329

1

npm run build 에러

0

519

1

front 서버 npm run build 중에 발생한 에러들

0

383

1

서버 실행하고 브라우저로 들어갔을때 404에러

0

338

2

css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.

0

289

1

팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.

0

240

2

해시태그 검색에서 throttle에 관해 질문있습니다.

0

202

1