DEV Community

loading...

Day 25 of 365 Days of Code

Mehak Saini
Java Developer by profession React enthusiast Currently exploring Blockchain
・1 min read

I came across a peculiar problem in my react application. The change handler of an input field was not passing the event object, rather only the value of the field was getting passed. I'm using rsuite and I think it uses Semantic-UI components somewhere, not sure, need to check more on this. Long story short, I fixed it by using the second argument of the handler function, didn’t know that existed.

//old version
const handleChange=(event)=>{
      console(event.target) // undefined
      console(event) // value of the object which should otherwise be event.target.value
}
Enter fullscreen mode Exit fullscreen mode
//new version
const handleChange=(value, event)=>{
...
}
Enter fullscreen mode Exit fullscreen mode

Also, I'm changing the challenge name to 30 days of Code. It looks rather achievable :P

Discussion (0)