Specifically, I am using react-semantic-ui's Select Form, which takes an onChange function. So I have defined my function as such:
const handleInputChange = function handleInputChange(event, data){// does something with data}
(don't mind the ugly syntax, that's airbnb style guide)
I am doing something with data, but I am not using the event parameter at all. What would be the best practice in this case, since it is generally a bad practice to declare a variable without using it?
You must declare a parameter for every argument before the one you want to use.
The idiomatic approach to marking a parameter as unused is to prefix its name with an underscore.
function handleInputChange(_event, data){
Some linters will recognise this and not emit a "unused variable" warning.
For example ESLint has a argsIgnorePattern option (but it also has a args option that lets you specify after-used).
Actually by using Js es6 you could code without unused argument:)
function handleInputChange(...[, data]) {
console.log(data);
}
handleInputChange('event', 123);
And bellow is a similar question you could check out:) Standard conventions for indicating a function argument is unused in JavaScript