【发布时间】:2020-04-12 02:58:47
【问题描述】:
我是非常新的 react.js。我将 react-select 用作带有 onClick 操作按钮的下拉菜单。我无法让 URL 动态更新。例如,用户在下拉菜单中选择 Netflix 并单击选择按钮,它会将他们重定向到 Netflix URL。如何使用带有按钮的 react-select 动态更新 URL 链接。
import Select, { components } from 'react-select';
import { Link } from "gatsby"
import homePageStyles from './home-page.module.scss'
const type = [
{ value: 'netflix', label: 'netflix' },
{ value: 'amazon', label: 'amazon' },
{ value: 'facebook', label: 'facebook'}
]
const searchButton = `${homePageStyles.button} ${homePageStyles.search}`
const Choose = (props) => (
<div>
{<div>CHOOSE</div>}
<components.Control {...props} />
</div>
);
export default class SearchStraws extends Component {
state = {}
render() {
return (
<div className={homePageStyles.product}>
<div className="call-product-container">
<div className={homePageStyles.callOut}>
<Select
isClearable
components={{ Control: Choose }}
isSearchable
options={type}
/>
</div>
<div className={homePageStyles.callOut}>
<button className={searchButton}>
<Link to="www.netflix.com">Search</Link>
</button>
</div>
</div>
</div>
)
}
}```
【问题讨论】:
标签: reactjs react-router gatsby react-select