reactjs - onClick 属性和函数是否暴露在 react-select 上?
问题描述
我想延迟 react-select 的选项元素上的 onClick 事件。
例子:
import React from "react";
import { components } from "react-select";
const Option = props => {
const { label, data, onClick } = props;
return (
<components.Option
{...props}
onClick={() => {
setTimeout(onClick, 100);
}}>
<div>Some custom stuff here</div>
</components.Option>
);
};
export default Option;
预期行为:
- 用户点击选项(在下拉列表中)
- react-select 不应该在 100ms 内做任何事情
- 100 毫秒后 react-select 完成他的工作
我已经用 props selectOption
, onChange
, 和and组件尝试过这个onClick
,但是没有用。Select
components.Options
解决方案
找到它:)
不确定它是否正确,但它有效。
const { innerProps } = props;
const { onClick } = innerProps;
props.innerProps.onClick = e => {
setTimeout(() => {
onClick(e);
}, 100);
};
推荐阅读
- ruby-on-rails - Ruby on Rails 'pg' gem 安装错误 Windows 10
- python - 使用一对一字段扩展 Django 用户框架,错误:唯一约束失败:userprofile_profile.user_id
- reactjs - TypeScript 中用于布尔道具的 Storybook 代码片段
- c# - Devops 构建管道 - 错误 MSB3073:命令 XCOPY
- node.js - 如何在 JEST 中模拟一个承诺和绑定的函数?
- r - 使用 rtweet 时如何选择下载时间段?
- ruby - 我应该将 ruby 单行 if 语句拆分为多行 if 语句,因为该行很长吗?
- java - 标记未显示在地图片段上
- javascript - PDF中的CSS未在服务器上加载
- r - 使用 Heroku Docker R Buildpack 在 Heroku 上的可扩展性 Shiny App