【问题标题】:onChange is not working in reactstrap custom input switchonChange 在 reactstrap 自定义输入开关中不起作用
【发布时间】:2021-08-31 02:18:10
【问题描述】:

代码:

import { CustomInput } from 'reactstrap'
...
const changeMediaStatus = (e) => {
   console.log(e)
}
...
<CustomInput
   type="switch"
   className="ml-auto mr-1"
   onChange={(e) =>changeMediaStatus(e)}
/>

在上面的代码中,“onChange”属性分配的函数不起作用。而且,带有 onChange 属性的 CustomInput 组件也不起作用。

如何在 reactstrap CustomInput 组件中为 onChange 事件分配函数?

【问题讨论】:

标签: javascript reactjs reactstrap


【解决方案1】:

为 CustomInput 提供 id。

<CustomInput
      type="switch"
      id="id-1"
      className="ml-auto mr-1"
      onChange={(e) => changeMediaStatus(e)}
    />

https://stackblitz.com/edit/reactstrap-1ttkao?file=Example.js

【讨论】:

    猜你喜欢
    • 2020-12-10
    • 2011-02-22
    • 2016-05-22
    • 2020-08-07
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多