Skip to content Skip to sidebar Skip to footer

Set Default Value Of Property Of Object Passed On Parameter To Function

The key difference on this question is I want to keep my property referenced inside the object, not destructured. export interface MapSettings { up: 'trueNorth' | 'runIn' | 'magn

Solution 1:

just check it and set it:

export const Map: FunctionComponent<MapProps> = function Map({
  settings,
}) {
  settings.rotation = (settings.rotation || settings.roation === 0) ? settings.rotation : 360

Solution 2:

Default value is mentioned as { someKey = 'defaultValue' } insead of `{ someKey: 'defaultValue' }

So you can write it like

{
   settings = { rotation: settingsRotation = 360 },
}

Post a Comment for "Set Default Value Of Property Of Object Passed On Parameter To Function"