简体   繁体   English

元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:未定义

[英]Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined

I'm new to react, so maybe it will sound stupid to ask. 我是新来的人,所以也许听起来很愚蠢。

I'm try to add a select input on my page but keep getting: 我正在尝试在页面上添加选择输入,但会不断得到:

ncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. ncaught Invariant Violation:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。

ncaught TypeError: Cannot read property '__reactInternalInstance$1y5rcyzngdmlzew7wenq4zpvi' of null ncaught TypeError:无法读取null的属性'__reactInternalInstance $ 1y5rcyzngdmlzew7wenq4zpvi'

My code is: 我的代码是:

import React from "react";
import {Input} from "react-bootstrap";

    render() {
            return (
                <div className="pickup-site-filter-container">
                    <span className="pickup-site-filter-label">Filter Locations by</span>
                    <span className="pickup-site-filter-zipCode">Zip Code:
                        <input className="filter-zipCode" type="text" pattern="[0-9]{5}" value={this.state.zipCode}
                               htmlFor="validation-error" ref="zipCode" onChange={this.onChangeZipCode}/>
                    </span>
                    <span className="pickup-site-filter-deliveryDay">Delivery Day:
                        <Input type="select" value="1" ref="valid_for">
                          <option value="1">1 hour</option>
                          <option value="2">1 day</option>
                          <option value="2">5 days</option>
                        </Input>
                    </span>
                    <button className="pickup-site-filter-btn" onClick={this.filterClicked}>FILTER</button>
                </div>)
        }

This is only the render cause i found out that also a select example doesn't work 这只是渲染原因,我发现选择示例也不起作用

I changed it to <select> instead using the <Input type='select'> and it worked 我将其更改为<select>而不是使用<Input type='select'> ,它可以正常工作

 createSelection() {
        let days = [];
        days.push(<option key={8} value="All" onChange={this.onChangeDeliveryDay}>All</option>);
        if(this.props.deliveryDays) {
            for (let i = 0; i <= this.props.deliveryDays.length; i++) {
                days.push(<option key={i} value={this.props.deliveryDays[i]} onChange={this.onChangeDeliveryDay}>{this.props.deliveryDays[i]}</option>);
            }
        }
        return days;
    },
    render() {
        return (
            <div className="pickup-site-filter-container">
                <span className="pickup-site-filter-label">Filter Locations by</span>
                <span className="pickup-site-filter-zipCode">Zip Code:
                    <input className="filter-zipCode" type="text" pattern="[0-9]{5}" value={this.state.zipCode}
                           htmlFor="validation-error" ref="zipCode" onChange={this.onChangeZipCode}/>
                </span>
                <span className="pickup-site-filter-deliveryDay">Delivery Day:
                    <select value="1" ref="valid_for">
                        {this.createSelection()}
                    </select>
                </span>
                <button className="pickup-site-filter-btn" onClick={this.filterClicked}>FILTER</button>
            </div>)
    }

您是否尝试过使用<select></select>代替<input type="select" />

暂无
暂无

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

相关问题 NextJS:元素类型无效:期望字符串(用于内置组件)或类/函数(用于复合组件)但得到:未定义 - NextJS: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 元素类型无效:预期字符串(用于内置组件)或类/函数(用于复合组件)但得到:未定义 - Element type is invalid: expected string (for built-in components) or a class/function (for composite components) but got: undefined 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 渲染错误元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Render Error Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 控制台错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Console error: Element type is invalid:expected a string (for built-in components) or a class/function (for composite components) but got: undefined ReactDOM - 元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - ReactDOM - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined React - 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - React - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 错误 - 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - error - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义。 在 nextjs 中 - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. in nextjs 未捕获的错误:元素类型无效:预期为字符串(内置组件)或类/函数(复合组件),但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (built-in components) or a class/function ( composite components) but got: undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM