Console logging for react?

后端 未结 3 1870
面向向阳花
面向向阳花 2021-01-29 23:31

I\'m super new to React and I\'m trying to get it set up for Meteor and piecing stuff together from other sources too. One of these other sources set up console logging for the

3条回答
  •  渐次进展
    2021-01-29 23:56

    Here are some more console logging "pro tips":

    console.table

    var animals = [
        { animal: 'Horse', name: 'Henry', age: 43 },
        { animal: 'Dog', name: 'Fred', age: 13 },
        { animal: 'Cat', name: 'Frodo', age: 18 }
    ];
    
    console.table(animals);
    

    console.trace

    Shows you the call stack for leading up to the console.

    You can even customise your consoles to make them stand out

    console.todo = function(msg) {
        console.log(‘ % c % s % s % s‘, ‘color: yellow; background - color: black;’, ‘–‘, msg, ‘–‘);
    }
    
    console.important = function(msg) {
        console.log(‘ % c % s % s % s’, ‘color: brown; font - weight: bold; text - decoration: underline;’, ‘–‘, msg, ‘–‘);
    }
    
    console.todo(“This is something that’ s need to be fixed”);
    console.important(‘This is an important message’);
    

    If you really want to level up don't limit your self to the console statement.

    Here is a great post on how you can integrate a chrome debugger right into your code editor!

    https://hackernoon.com/debugging-react-like-a-champ-with-vscode-66281760037

提交回复
热议问题