Search code examples
javascriptreactjsreactstrap

onChange is not working in reactstrap custom input switch


Code:

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

On the above code, the function that is assigned at "onChange" prop is not working. And also, CustomInput component with onChange prop is not working.

How can I assign a function to onChange event at reactstrap CustomInput compoenent?


Solution

  • Provide id for the CustomInput.

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

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