강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của jojov2
jojov2

câu hỏi đã được viết

[Gia hạn] Tạo NodeBird SNS bằng React

Tạo dữ liệu giả và postform

제로초님..!

Đã giải quyết

Viết

·

414

0

TypeError: imageInput.current.click is not a function

에러가 나고 있어요.. 콘솔에 찍어봐도 click은 안보이고 검색해보고 비교도 해봤는데 도저히 못찾겠네요 ㅡㅠ  코드 한번만 봐주세욥..

import { Button, Form, Input } from "antd";
import React, { useCallback, useRef } from "react";
import { useDispatch, useSelector } from "react-redux";
import useInput from "../hooks/useInput";
import { addPost } from "../reducers/post";

const PostForm = () => {
  const dispatch = useDispatch();
  const imageInput = useRef();
  const [text, onChangeText, setText] = useInput("");
  const { imagePaths } = useSelector((state) => state.post);
  const onSubmit = useCallback(() => {
    dispatch(addPost);
    setText("");
  }, []);

  const onClickImageUpload = useCallback(() => {
    imageInput.current.click();
  }, [imageInput.current]);
  return (
    <Form
      style={{ margin: "10px 0 20px" }}
      encType="multipart/form-data"
      onFinish={onSubmit}
    >
      <Input.TextArea
        value={text}
        onChange={onChangeText}
        maxLength={140}
        placeholder="어떤 신기한 일이 있었나요?"
      />
      <div>
        <Input type="file" multiple hidden ref={imageInput} />
        <Button onClick={onClickImageUpload}>이미지 업로드</Button>
        <Button type="primary" style={{ float: "right" }} htmlType="submit">
          짹짹
        </Button>
      </div>
      <div>
        {imagePaths.map((v) => (
          <div key={v} style={{ display: "inline-block" }}>
            <img src={v} style={{ width: "200px" }} alt={v} />
            <Button>제거</Button>
          </div>
        ))}
      </div>
    </Form>
  );
};

export default PostForm;

reactreduxexpressnodejsNext.js

Câu trả lời 5

0

저도 같은 에러에서 헤매다가 코드 수정했네요. 질문 감사드려요

0

YOUNG EUN님의 프로필 이미지
YOUNG EUN
Người đặt câu hỏi

제로초님...! 죄송해요!

오타였어요 ㅜㅠ Input으로 했더라구요!

감사합니당!

0

YOUNG EUN님의 프로필 이미지
YOUNG EUN
Người đặt câu hỏi

<Input type="file" multiple hidden innerRef={imageInput} />

이렇게 바꾸는거 맞죠?? 바꾸면 

react_devtools_backend.js:2574 Warning: React does not recognize the `innerRef` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `innerref` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

이런 에러가 떠욥..!  그리고 콘솔로 imageInput.current 치면 null로나와요 ㅜㅠ

0

YOUNG EUN님의 프로필 이미지
YOUNG EUN
Người đặt câu hỏi

이렇게 뜹니다..!ㅜㅠ

zerocho님의 프로필 이미지
zerocho
Người chia sẻ kiến thức

바꿨는데도 이렇게 뜬다구요??

YOUNG EUN님의 프로필 이미지
YOUNG EUN
Người đặt câu hỏi

넵.... 

zerocho님의 프로필 이미지
zerocho
Người chia sẻ kiến thức

ref 대신 innerRef로 바꾸면 어떤가요?

0

zerocho님의 프로필 이미지
zerocho
Người chia sẻ kiến thức

imageInput.current?.click()으로 바꿔보세요.

Hình ảnh hồ sơ của jojov2
jojov2

câu hỏi đã được viết

Đặt câu hỏi