해결된 질문
작성
·
311
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;
답변 5
0
0
0
<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
바꿨는데도 이렇게 뜬다구요??