【问题标题】:Dropdown menu creattion - const error - Unexpected error, syntax needed ';'下拉菜单创建 - 常量错误 - 意外错误,需要语法 ';'
【发布时间】:2019-03-06 03:28:56
【问题描述】:

下面是代码,基本上我试图根据用户输入制作一些下拉框,以建议适合他们情况的完美啤酒。我正在尝试添加下拉菜单,但我在第 11 行通过 const 得到了这个“意外令牌”。我们将不胜感激,或者更深入地了解如何制作下拉菜单并将它们与图片配对?

What I would like, is to make 1 drop down bar that has a lift of about 10-15 beers that will correspond with an image when a beer from the list is selected

import React from "react";
import Dropdown from 'react-dropdown';
import 'react-dropdown/style.css';

const defaultOption = options[0];
<Dropdown options={options} onChange={this._onSelect} value={defaultOption} placeholder="Select an option"/>

const Form = props => (
  <form onSubmit={props.getBeer}>
    <input type="text" name="beerName" />
    <button>Search</button>
  </form>
);


const options = [
  { value: 'one', label: 'One' },
  { value: 'two', label: 'Two', className: 'myOptionClassName' },
  {
   type: 'group', name: 'group1', items: [
     { value: 'three', label: 'Three', className: 'myOptionClassName' },
     { value: 'four', label: 'Four' }
   ]
  },
  {
   type: 'group', name: 'group2', items: [
     { value: 'five', label: 'Five' },
     { value: 'six', label: 'Six' }
   ]
  }
]



export default Form;

【问题讨论】:

  • 我不知道反应语法,但你确定在&lt;Dropdown 之后有; 插入在Dropdownoption={...} 之间

标签: javascript reactjs token unexpected-token


【解决方案1】:
<Dropdown; options={options}, onChange={this:_onSelect}, value={defaultOption}, placeholder="Select an option">Dropdown>

正如 Yashwardhan Pauranik 指出的那样,删除 ;在&lt;Dropdown; 中并关闭结束的下拉标签?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-02-25
  • 1970-01-01
相关资源
最近更新 更多