Pass Props to a Stateless Functional Component Bug?

Hey guys what do you think is the problem with my code?

Your code so far



const CurrentDate = (props) => {
  return (
    <div>
      { /* change code below this line */ }
      <p>The current date is: {props.date.toLocaleTimeString()}</p>
      { /* change code above this line */ }
    </div>
  );
};

class Calendar extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div>
        <h3>What date is it?</h3>
        { /* change code below this line */ }
        <CurrentDate date={new Date()}/>
        { /* change code above this line */ }
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:

I have passed all test except the last two at the bottom:

remove new from CurrentDate date={new Date()}

1 Like

@lubodrinka Can you explain why we don’t need ‘new’ in front of Date() ?

because in introduction last words are date={Date()}.

You can still use new Date() but with additional function to convert it to string like this: new Date().toLocaleTimeString() you can read it on react’s tutorial: https://reactjs.org/docs/rendering-elements.html

1 Like