isAuth is not defined
i defined isAuth in Line 14 but i got error "src\App.js Line 25:13: 'isAuth' is not defined no-undef" idk, maybe i defined it wrong, looking up for your help, thanks
import React, { Component } from 'react';
import './css/main.css';
import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom';
import Home from './pages/Home';
import CreatePost from './pages/CreatePost';
import Login from './pages/Login';
class App extends Component {
constructor(props) {
super(props);
this.state = {
isAuth: false,
setIsAuth: false
};
}
render() {
return (
<Router>
<nav>
<Link to="/">Home</Link>
<Link to="/createpost"> Create New Post</Link>
{!isAuth && <Link to="/login">Login</Link>}
</nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/login" element={<Login setIsAuth={this.state.setIsAuth} />} />
<Route path="/createpost" element={<CreatePost />} />
</Routes>
</Router>
);
}
}
export default App;
To access a property of the state, you need to add this.state.
like this :
{!this.state.isAuth
or this :
render() {
const { isAuth } = this.state;
return (