Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
ternary object is not working in react cant pass props
import React, { Fragment, useState } from "react";
import "./App.css";
import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom";
import Home from "./components/Home";
import Login from "./components/Login";
import Register from "./components/Register";

function App() {

const [isAuthenticated, setAuthenticated] = useState(false);

function App() {

const [isAuthenticated, setAuthenticated] = useState(false);

return (
    <Fragment>
        <Router>
            <div className="container">
                <Routes>
                    <Route
                        exact
                        path="/login"
                        element={props => !isAuthenticated ? <Login {...props}/> :<Link to="/home" />}
                    />
                    <Route
                        exact
                        path="/register"
                        element={props => !isAuthenticated ? <Register {...props} /> : <Link to="/login" />}
                    />
                    <Route
                        exact
                        path="/home"
                        element={props => !isAuthenticated ? <Home {...props} />: <Link to="/login" />}
                    />
                
                </Routes>
            </div>
        </Router>
    </Fragment>
);

}

export default App;

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

function App(props){
    //props accessible now to the functional component
    return(
        //your code...
        {
            !(isAuthenticated)?
            <Routes>
                <Route
                    exact
                    path="/login"
                    element={<Login {...props}/>}
                />
                //other unauthenticated routes
            </Routes>
            :
            <Routes>
                <Route
                    exact
                    path="/login"
                    element={<Link to="/home" />}
                />
                //other authenticated routes
            </Routes>
        }
    )
}
  • props would be accessible to routes if they exist on App component.
  • you can have 2 sets of authenticated and unauthenticated routes to set based on the authentication state.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!