![]() Using console.table(users) in the render we will be able to produce the below table and check the data is as expected, without having to build out our table component in the ui. In the below example our api call returns a json of users and they are stored in the state. Using the columns parameter you can display in the console only the columns of data that you are actually watching Going back to React, a common pattern is to store a server response in your state, often there is data involved that will not be used in the component you are working on. By using this you are able to parse an array of large objects and select only the columns relevant to you. The columns parameter takes an array of column names or values and allows you to select the values you would like displayed. Where this really comes in useful is the columns parameter.Īs a default the columns.table() will list all the elements in an object. ![]() If the calling file is in the same directory, you can just reference the script name. Check your spelling of the 'src' attribute. You can also shoot me a text if you cant find a time that works and I can try to make something work Need something today We still have a space in town on. Using the console in Chrome dev tools we can see console.table () at work The function console. Console is not part of JavaScript, but instead is an implementation of the browser itself. Console.table () Console.table is a great way of logging to the console that will parse your data and log in the console as a table. Note that in Firefox console.table() is currently limited to 1000 rows Sounds as if you're not providing the correct path the your scripts.js file, thus it is not getting executed. The table also works as you would expect allowing you to sort the column by clicking on the title. The first column will be labelled index and in the case of an array it will display the indices, while an object will display the Key or property names. The function console.table() takes either an array or an object and can also take an optional parameter ‘columns’ ![]() Using the console in Chrome dev tools we can see console.table() at work When your state is simple and you have one or two values to monitor, console.log() is great but when you start adding more to your component state especially in a Class component this can start getting very ugly as your state object being output is minified.Ĭonsole.table is a great way of logging to the console that will parse your data and log in the console as a table. I work in React and being able to console log your state and check that the components are rendering as expected is a key development pattern. The ability to log data and check that it renders as expected in the browser allows you to quickly debug specific parts of your code in a quick and neat fashion. As a front end developer one of the key tools in my debugging arsenal is the console log. ![]()
0 Comments
Leave a Reply. |