강의

멘토링

커뮤니티

Inflearn Community Q&A

yimjh23093165's profile image
yimjh23093165

asked

[Renewal] Creating NodeBird SNS with React

Implementing comments

댓글 구현하기 중 콘솔창에 출력이 안됩니다..

Written on

·

577

0

댓글창에 텍스트 입력후 버튼을 누르면

id는 출력이되는데 e.target.value가 출력이 안됩니다..

그런데 한참 지나면 또 출력이 됬다가 안됬다가 합니다..

Next가 인식이 잘 안되어서 그런걸까여?

 

아래는 커스텀 훅은 코드 와

CommentForm 코드 입니다..

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];
};
import React, { useCallback } from "react";
import { Button, Form, Input } from "antd";
import useInput from "../hooks/useInput";
import PropTypes from "prop-types";
import { useSelector } from "react-redux";

const CommentForm = ({ post }) => {
  const id = useSelector((state) => state.user.me?.id);
  const [commentText, onChangeCommentText] = useInput("");
  const onSubmitComment = useCallback(() => {
    console.log(post.id, commentText);
  }, []);
  return (
    <Form onFinish={onSubmitComment}>
      <Form.Item>
        <Input.TextArea
          value={commentText}
          onChange={onChangeCommentText}
          rows={4}
        />
        <Button type="primary" htmlType="submit">
          삐약
        </Button>
      </Form.Item>
    </Form>
  );
};

CommentForm.propTypes = {
  post: PropTypes.object.isRequired,
};

export default CommentForm;
expressreactnodejsreduxNext.js

Answer 3

1

zerocho님의 프로필 이미지
zerocho
Instructor

useCallback [] 안에 post랑 commentText 넣어야합니다.

hyuri님의 프로필 이미지
hyuri
Questioner

오! 감사합니다!!!!!!!
이시간에 빠른 답변도 너무 감사합니다!

hyuri님의 프로필 이미지
hyuri
Questioner

아 추가로 <Form.Item style={{ position: 'relative', margin: 0 }}>

폼 아이템에 인라인 스타일을 넣으면

버튼 작동이 안되는데.. 이건 왜그럴까요?

넣지 않으면 작동이 잘됩니다..ㅠㅠ

0

hyuri님의 프로필 이미지
hyuri
Questioner

그냥 빼도 될까요

zerocho님의 프로필 이미지
zerocho
Instructor

버튼이 안돌아가는건 좀 이상한데요. 다른게 버튼 위를 가리고있어서 그런거 아닐까요

hyuri님의 프로필 이미지
hyuri
Questioner

아 그런가요 ㅠㅠ 나중에 한번 천천히 살펴 보겠습니다. 감사합니다!

0

hyuri님의 프로필 이미지
hyuri
Questioner

margin을 빼면 또 됩니다..

yimjh23093165's profile image
yimjh23093165

asked

Ask a question