Destructuring change name and set default value

Viewed 2679

How can I destructure the nested routes and index and set a default value?

const {
    nav: { index: navIndex = '', routes: navRoutes = '' }
    routes = '', index = ''
} = _navigator.state;

I'd like to rename the nested values to navIndex and navRoutes, any ideas?

1 Answers

You could take a default object for not given nav object

const {
        nav: { index: navIndex = '', routes: navRoutes = '' } = {}, 
        routes = '', 
        index = ''
    } = _navigator.state;
Related