Pass Props to a Stateless Functional Component Bug?

Pass Props to a Stateless Functional Component Bug?
0.0 0

#1

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:
https://learn.freecodecamp.org/front-end-libraries/react/pass-props-to-a-stateless-functional-component

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


#2

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


#3

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


#4

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


#6

new Date() returns an object and Date() returns a string with the current date/time (UTC)


#7

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