2

I am passing an object to a function. I want to destructure some of the child object, but also have a reference to the original parent object. I hope this illustrates what I mean :

let state = {
    objectA: {},
    objectB: {},
    objectC: {}
}

const mapStateToProps = ({ objectA, objectB}, state) => {

    let a = objectA;
    let b = objectB;
    let c = state.objectC;
};

mapStateToProps(state);

I want to be able to destructure some of the objects, but then also have a reference to the original state object.

Is it possible to do this ?

Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
  • 1
    Just don't destructure in the parameter list if you want to access the whole argument. – Bergi Feb 22 '19 at 13:56

1 Answers1

3

You could take a classic function and use arguments.

In arrow functions, you have no access to arguments.

let state = { objectA: {}, objectB: {}, objectC: {} }

const mapStateToProps = function ({ objectA, objectB }) {
    let a = objectA;
    let b = objectB;
    let c = arguments[0].objectC;
    console.log(a);
    console.log(b);
    console.log(c);
};

mapStateToProps(state);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392