i want to set an optional parameter to a function using javascript. i have a function defined like below,
const function1 = () => {
setValue(!open);
};
i call it like below in other function
const main_function = () => {
function1();
}
now i want to pass an optional parameter to function1 to accept an optional parameter that sets it to true or false instead of toggling based on previous value.
how can i fix this. could someone help me with this thanks.
function1 = (optionalParam = false) => {}setValue(!open);don't do this. Use functional update as your new state depends on the previous state.setValue(prevState => !prevState).function1()orfunction1(true)orfunction1(false)