javascript - React 不允许我使用 React.Fragment

标签 javascript reactjs

我在尝试托管我的网络应用程序时收到此错误。问题似乎出在 React.Fragment 调用上。

×
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

Check your code at search-input.js:8.
SearchInput
src/components/search-input.js:8
   5 | 
   6 | //This is the Presentation component
   7 | const SearchInput = ({searchInput}) =>
>  8 |   <React.Fragment>
   9 |     <div>{searchInput}</div>
  10 |   </React.Fragment>
  11 | 
View compiled
Search
src/containers/search.js:47
  44 |     <input onChange={(input) => this.searchInput(input)}></input>
  45 |   </div>
  46 |   <div className='row'>
> 47 |     <SearchInput searchInput = {this.state.searchInput}/>
  48 |     <button onClick={this.buttonClick} className='btn btn-danger btn-xs'>SEARCH</button>
  49 |   </div>
  50 | </div>
View compiled
Search
src/containers/search.js:41
  38 | 
  39 | render(){
  40 |   return(
> 41 |     <div className='search'>
  42 |       <div className='row'>
  43 |         <h1>Sentiment</h1>
  44 |         <input onChange={(input) => this.searchInput(input)}></input>
View compiled
Welcome
src/welcome.js:12
   9 | const Welcome = ({}) =>
  10 |   <div className='row'>
  11 |     <div className='col-xs-5'>
> 12 |       <Search/>
  13 |       <Link to="/search">
  14 |           <button className='btn btn-xs'>Go to Map</button>
  15 |       </Link>
View compiled
App
src/App.js:23
  20 | <h1 className="App-title">{this.state.title}</h1>
  21 | 
  22 | {/* We rended diffrent component based on the path */}
> 23 | <Route exact path="/" component={Welcome}/>
  24 | <Route path="/search" component={Discover}/>
  25 | 
  26 | 
View compiled
App
src/App.js:19
  16 | render() {
  17 |   return (
  18 |     <div className="App">
> 19 |       <header className="App-header">
  20 |         <h1 className="App-title">{this.state.title}</h1>
  21 | 
  22 |         {/* We rended diffrent component based on the path */}
View compiled
(anonymous function)
src/index.js:10
   7 | 
   8 | ReactDOM.render((
   9 |     <BrowserRouter>
> 10 |         <App />
  11 |     </BrowserRouter>
  12 | ), document.getElementById('root'));
  13 | 
View compiled
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.

我不知道是什么原因导致了这个错误。我假设 React.Fragment 已正确导出,所以我猜测我的 react 安装有问题。我该如何解决这个问题?

最佳答案

确保您使用的是 React@^v16.2.0

关于javascript - React 不允许我使用 React.Fragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49770972/

相关文章:

php - $.post 函数未返回正确的数据

javascript - 如何在div之间绘制响应线

javascript - 使用带有动态 header 的数据表在我的网站上显示 mysql 结果

javascript - 如何发出多个http请求?

javascript - 如何在公共(public)文件reactjs中包含文件?

javascript - 如何在react中使用全局配置

javascript - 如何调用一系列 Promise 函数?

javascript - Webpack 分块。没有内容出现 - block 未加载

javascript - 我如何在我的 React 页面中使用 jquery/html/css 组件

javascript - react JS : Rendering object keys and its values