This seems like a stupid question. Say I have a function which accepts an object. How can I cast that object as props
, but also destructure props.id
to id
(in the parameter declaration)?
function go ({ id }) {
const props = arguments[0]; // how to do this with destructure?
console.log('props', props, 'id', id);
}
go({id: 2});
You can't do it - just keep props
as an argument as well to make this code simpler and easier to read:
function go (props) {
const { id } = props;
console.log('props', props, 'id', id);
}
go({id: 2});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With