0

I am working on a React Native app.

I want to be able to call the useAppTracking function with an id if id exists, and pass in an empty object if id doesn't exist. When attempting to assign a default value to id, I hit an error because I am reassigning a const. Can someone show me a best-practices way to accomplish what I need, please?

  const { id } = route.params;
  ...
  useAppTracking('Goal', id || {});
dereknahman
  • 87
  • 1
  • 9
  • provide the full context of your code – michael Dec 24 '20 at 14:49
  • 1
    `const { id = {} } = route.params` [Destructuring with default values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Default_values_2) – adiga Dec 24 '20 at 14:51

0 Answers0