Luke De Feo
Luke De Feo

Reputation: 2165

React native how to execute code in breakpoints context

I am using

I want to stop at a breakpoint and execute code. i can stop at breakpoints. i seem to be able to access local vars in the console but i cannot see what my this var that i import

import {images} from '../assets/index';

This is the contents of that file

export const images = {
    Level_4_Hallway: require("./images/floorplans/Level_4_Hallway.jpg"),

};

I tried to require it in the console but i dont know what my path is. For some reason require works in vscode but not in chrome debugger

Upvotes: 0

Views: 363

Answers (2)

Matt McCutchen
Matt McCutchen

Reputation: 30929

If you look at the enclosing scopes in the "Variables" panel in VS Code, one of them should have local variables corresponding to your imports. The precise naming and meaning of those variables is dependent on the module bundler, which in the case of React Native is Metro. I did a simple test and it looks like the name of the imported module is converted to camel case and prefixed with an underscore, and in some cases, a suffix of 2 is added.

If all else fails, add code to your program to copy the import to a local variable, e.g.:

const images2 = images;

Upvotes: 1

Tareq El-Masri
Tareq El-Masri

Reputation: 2573

Use debugger; to create your breakpoint and enable debugging

debugger;
export const images = {
    Level_4_Hallway: require("./images/floorplans/Level_4_Hallway.jpg"),

};

Upvotes: 0

Related Questions