inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

리렌더링 이해하기

LoginForm 컴포넌트에서 props로 setIsLoggedIn을 받아올 때 질문입니다!

197

워니

작성한 질문수 13

0

LoginForm 컴포넌트에서 AppLayout 컴포넌트의 props로 setIsLoggedIn을 받아올 때 밑에 빨간 줄이 뜨네요!

위 경고(?) 메시지가 떠서 구글 찾아보면서 propTypes 적용해봤는데
setIsLoggedIn이 isLoggedIn의 상태를 바꾸는 함수라 생각하여 아래와 같이 작성해봤는데 맞는지 여쭤보고 싶습니다!

빠르게 보시라고 LoginForm 컴포넌트 내용 전체 올릴게요!

import React, { useState, useCallback } from 'react';
import propTypes from 'prop-types';
import { Form, Input, Button } from 'antd';
import Link from 'next/link';
import styled from 'styled-components';

const ButtonWrapper = styled.div `
  margin-top: 10px;
`; // 백틱 안에는 CSS 적듯이 적으면 됨
// div 태그이면서 css가 적용된 ButtonWrapper 컴포넌트 사용 가능

const LoginForm = ({ setIsLoggedIn }) => {
  const [id, setId] = useState('');
  const [password, setPassword] = useState('');

  const onChangeId = useCallback((e) => {
    setId(e.target.value);
  }, []);

  const onChangePassword = useCallback((e) => {
    setPassword(e.target.value);
  }, []); 

  // 배열 안에 id, password 작성하지 않으면 초기값을 기억하기 때문에 넣어줘야 함
  const onSubmitForm = useCallback(() => {
    console.log(id, password);
    setIsLoggedIn(true);
  }, [id, password]);

  return (
    <Form onFinish={onSubmitForm}>
      <div>
        <label htmlFor="user-id">아이디</label>
        <br />
        <Input name="user-id" value={id} onChange={onChangeId} />
      </div>
      <div>
        <label htmlFor="user-password">비밀번호</label>
        <Input
          name="user-password" 
          type="password"
          value={password}
          onChange={onChangePassword}
          required
        />
      </div>
      <ButtonWrapper>
        <Button type="primary" htmlType="submit" loading={false}>로그인</Button>
        <Link href="/signup"><a><Button>회원가입</Button></a></Link>
      </ButtonWrapper>
    </Form>
  );
};

LoginForm.propTypes = {
  setIsLoggedIn: propTypes.func.isRequired,
};

LoginForm.defaultProps = {
  setIsLoggedIn: () => console.warn('setIsLoggedIn 값이 없습니다')
};

export default LoginForm;

 

react redux express nodejs Next.js

답변 1

1

제로초(조현영)

네 정확합니다!

0

워니

감사합니다:)

넥스트 버젼 질문

0

91

2

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

0

104

1

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

0

199

1

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

0

117

2

createGlobalStyle의 위치와 영향범위

0

104

2

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

0

98

2

vsc 에서 npm init 설치시 오류

0

159

2

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

0

166

1

화면 새로고침 문의

0

129

1

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

0

164

2

Next 14 사용해도 될까요?

0

455

1

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

0

359

1

url 오류 질문있습니다

0

218

1

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

0

394

1

sudo certbot --nginx 에러

0

1298

2

Minified React error 콘솔에러 (hydrate)

0

482

1

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

0

257

1

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

0

341

1

npm run build 에러

0

526

1

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

0

399

1

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

0

351

2

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

0

291

1

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

0

252

2

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

0

207

1