Pass Props to a Stateless Functional Component :: Typo in Instructions?

Tell us what’s happening:

The date prop of the CurrentDate should contain a string of text.

Isn’t the above statement(instruction) is misleading ? because my date property will look like below

<CurrentDate date={Date()}/>

I’m calling a JS Date object directly, I shouldn’t pass this as a string of text like

I’m just curious if there is any mistake in the instructions or may be I’m going wrong

Can someone please guide me ? Thanks !!

Your code so far


const CurrentDate = (props) => {
return (
  <div>
    { /* change code below this line */ }
    <p>The current date is:, {props.date} </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={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/80.0.3987.87 Safari/537.36.

Challenge: Pass Props to a Stateless Functional Component

Link to the challenge:
https://www.freecodecamp.org/learn/front-end-libraries/react/pass-props-to-a-stateless-functional-component

You may want to read a bit more about Date(). Take a look at https://devdocs.io/javascript/global_objects/date

Of specific interest to your case is this line, last line in the Description section:

Invoking JavaScript Date as a function (i.e., without the new operator) will return a string representing the current date and time.

2 Likes

Invoking JavaScript Date as a function (i.e., without the new operator) will return a string representing the current date and time.

Yeah and @idurisurya you can check it yourself too by doing

console.log(Date()); 
OR
console.log(typeof Date());
1 Like

Thank you !! it’s been a long time since I looked at JS, just directly jumped into React stuff. This taught me to go back and get some basics done from JS side :smiley:

1 Like

Keep a tab open to https://devdocs.io/, its a thing you might want to reference often. I’ve been coding since 1983, and I spend a LOT of time there. Kind of a backup for my poor old brain.

1 Like