Sorry, I added this part of the code that was missing, excuse me.
import React from 'react';
import './App.css';
function Timer(props){
constructor(props)
{
super(props);
this.state = {
clock: 0
};
}
return (
<div className="Timer">
<p>You have been on this site since: </p><br />
<span>{this.state.clock}</span><br /><p> seconds.</p>
</div>
);
}
export default Timer;
It gives me an error as if 'props' was not defined but if I pass it as an argument to the constructor and also to the super, I don't know what is wrong, help and thanks in advance to whoever takes the time to give me the appropriate instructions.
Line 4; 'props' is not defined no-undef
Line 6: 'props' is not defined no-undef`
Here the React code begins, thanks again guys, I don't understand why it gives me this strange error.
import React from 'react';
import logo from './logo.svg';
import './App.css';
import Timer from './Timer';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>Welcom to Timer app built in React.</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<Timer start={Date.now()}/>
</div>
);
}
export default App;
This is the answer!! thanks anyway :D
You have to pass them to the function.
The answer is because in a function component you can't add a constructor, since it won't create an "instance" of said component as if you did a class component, which do call a constructor every time you create one. new instance.