简体   繁体   中英

How to console.log props in React?

I'm new to React and have been thrown in the deep end with a task.

I must adjust the data for a date props. This looks (as far as I can tell) like:

form.defaultProps = {
  conf: {},
  minDate: new Date(),
  maxDate: new Date(new Date().setFullYear(new Date().getFullYear() + 2)),
};

I want to test if maxDate is the prop I am after. To do that I want to console.log (or equivalent) its output.

Would anyone know how I should be doing this?

You should be able to just log it directly:

console.log(form.defaultProps);

Most likely, you might want to this within the form component you are creating by calling console.log(this.props) .

As others are saying, you can simple do console.log(this.props) somewhere. I usually put it in the render() function so that every time there's an update to props or state, it will be logged again.

But if your sole purpose is to examine the props values for development, I'd recommend you to use React Devtools extension .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM