简体   繁体   English

“输入”未定义 react/jsx-no-undef,这是什么意思?

[英]'Input' is not defined react/jsx-no-undef, what does that mean?

Im trying to make an input field for name in my code, and I get: 'Input' is not defined react/jsx-no-undef and I cant see whats wrong, can anyone please help me?我试图在我的代码中为名称创建一个输入字段,我得到:'Input' is not defined react/jsx-no-undef,我看不出有什么问题,谁能帮帮我?

I will later pass name into my dispatch我稍后会将名称传递到我的调度中

The form part with textarea is working.带有 textarea 的表单部分正在工作。

import React, { useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import '../styles/NewMessage.css'
import { fetchNewMessage } from 'reducer/messages'

export const NewMessage = () => {
  const [message, setMessage] = useState('')
  const [name, setName] = useState('')

  const dispatch = useDispatch()


  const handleMessageSubmit = (event) => {
    event.preventDefault()
    //console.log('addNewMessage', message)

    dispatch(fetchNewMessage(message))
    setMessage('')
  }

  return (
    <div className="add-message-container">

      {/* ******Form for sending a new message******* */}
      <form onSubmit={handleMessageSubmit} className="add-message-form">

        <span>
          <label>
            Name:

This input is giving me the 'Input' is not defined react/jsx-no-undef这个输入给了我“输入”没有定义 react/jsx-no-undef

            <Input
              placeholder="Name"
              type="text"
              onChange={event => setName(event.target.value)}
              value={name}
              required
            />
          </label>
        </span>

This textarea is working fine这个文本区域工作正常


        <span>
          <label For="new-message">
            <textarea
              id="new-message"
              className="input-message"
              rows='3' 
              minLength='5'
              maxLength='150'
              placeholder="Type your message"
              onChange={(event) => setMessage(event.target.value)} 
              value={message}
              required />
          </label>
        </span>


        {/* * Form submit button * */}
        <div className="add-message-btn-container">
          <button
            className="add-message-btn"
            type="submit"
            title="Send">
            Send
          </button>
        </div>
      </form>
    </div>
  )
}

it is <input> tag with small i.它是带有小 i 的<input>标签。

You either need to import Input component from some component library or you need to use input which is the HTML element.您要么需要从某个组件库中导入Input组件,要么需要使用 HTML 元素的input JSX tags are case-sensitive, which is why it gives you are warning from eslint JSX 标签区分大小写,这就是为什么它会给你来自 eslint 的警告

      <input
          placeholder="Name"
          type="text"
          onChange={event => setName(event.target.value)}
          value={name}
          required
        />

Use <input /> instead of <Input /> , as JSX attributes are case-sensitive使用<input />而不是<Input /> ,因为 JSX 属性区分大小写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM