Passing Thoughts Project (Step 12 issue)

This is my first time asking a question here, so please bear with me if I mess something up.

My query regards the Passing Thoughts Project (Function Components and Hooks | Codecademy). More specifically, step 12, in which you are asked to write the following code into our function in Thought.js:

useEffect(() => {
  const timeRemaining = thought.expiresAt -;
  const timeout = setTimeout(() => {
    alert('Time has passed!');
  }, timeRemaining);
  return () => {
}, [thought]);

My question is, where is ‘setTimeout’ coming from? We haven’t declared a state hook in our function (see below for an example, in case I’ve used the wrong term here), so I am not sure how it works (and the code does work, but that part just confuses me). I have a similar query with ‘clearTimeout’.

export function Thought(props) {
  const [timeout, setTimeout] = useState();

Thanks in advance for any help you can provide. :slightly_smiling_face:

1 Like

Good observation.

setTimeout and clearTimeout don’t have anything to do with state hooks.

Have a look at:

1 Like

Gosh, do I feel silly! I didn’t even think to just look it up (which is usually the first thing I do), I was so set on the fact that I thought it was something to do with hooks, I didn’t even think that it might be a predetermined method.

All I will say is that I haven’t come across it before in the Full Stack path, and that there wasn’t really an explanation of what (or how) it works. Plus, in the context of the lesson, I hope you can see where I got confused (when we set state it does look awfully similar).

Thank you so much for the simple and concise answer. :smiley:

1 Like