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

138
Views
Pass props to child component rendered by React router

I'm trying to pass data from NavBar.js to a child component Mybooks.js which has already been rendered by React router, then, I get double rendering. Routing is happening in App.js.

NavBar.js

const AlreadyConnected = () => {

    return(
      <div>
        <MyBooks address={walletAddress}/>
      </div>
    )
  }

  return(
    <div>
      {walletAddress ? AlreadyConnected() : null}
    </div>
  )
};

MyBooks.js

import React, { useEffect } from 'react'

const MyBooks = ({address}) => {

    console.log(address);
    const URL = `http://localhost:3001/api/tatumapi`;
    const chain = 'ETH';
    const params = { address: address, chain: chain };

    useEffect(() => {
        fetch(URL,
            {
                method: 'POST',
                mode: 'cors',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(params)
            })
            .then(response => response.json())
            .then(data => console.log(data));
    }, [])

    return(<div>TEST</div>)
}

Apps.js

import { NavBar } from './pages/NavBar';
import MyBooks from './pages/MyBooks';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';

const App = () => {

    return (
        <Router>
            <div>
                <NavBar />
                <div>
                    <Routes>
                        <Route path='/' element={<MyBooks />} />
                    </Routes>
                </div>
            </div>
        </Router>
    )
}

export default App;

Output:

TEST
TEST

How to pass props from NavBar.js to MyBooks.js without rendering the same component twice?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Sounds like what you are trying to do is conditional rendering, maybe you should try this -

return(
    <div>
        {walletAddress && <MyBooks address={walletAddress}/> }
    </div>
    )

Check your code files upto index.js for this wrapper line of <React.StrictMode>. Default development mode can sometimes contain this line and it causes a double render in development mode to allow identifying errors

about 4 years ago · Santiago Gelvez 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!