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

107
Views
open a page with specific id in react

I have three pages here (App.js - Button.js - Template.js)
I want when user clicks on each button in Button.js, Template.js page to open with a specific data from api(Here I have an Artificial api contains with objects each object contains specific info about digital curency)I want when I click on for example bitcoin button template page renders with bitcoin info in it

App.js

import { useState } from "react";
import Button from "./Button";
import { BrowserRouter, Routes, Route, Link } from "react-router-dom";
import Template from "./Template";
const api = [
{ id: 1, name: "bitcoin", abbr: "btc" },
{ id: 2, name: "theter", abbr: "ttr" },
{ id: 3, name: "ethereum", abbr: "eth" },
];

export default function App() {
return (
    <BrowserRouter>
        <Routes>
            <Route path="/template" element={<Template data={api}/>} />
            <Route path="/button" element={<Button data={api}/>} />
        </Routes>
    </BrowserRouter>
 );
 }

Button.js

import React from "react";
import { Link } from "react-router-dom";

export default function Button(props) {
console.log(props.data);
return (
    <div>
        {props.data.map((item) => {
            return (
                <Link to={`/template`}>
                    <button btn-id={item.id}> {item.name}deposit</button>
                </Link>
            );
        })}
    </div>
 );
 }

Template.js

import React from "react";

export default function Template({ data }) {
console.log(data);
return (
    <div>
        {/* name */}
        <h1>Lorem.</h1>
        {/* abbr */}
        <span>hasan</span>
        {/* id */}
        <p>
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Inventore,
            consequatur.
        </p>
    </div>
);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you want to use URL params.

https://v5.reactrouter.com/web/example/url-params

https://v5.reactrouter.com/web/api/Hooks/useparams

App.js

import { useState } from "react";
import Button from "./Button";
import { BrowserRouter, Routes, Route, Link } from "react-router-dom";
import Template from "./Template";
const api = [
{ id: 1, name: "bitcoin", abbr: "btc" },
{ id: 2, name: "theter", abbr: "ttr" },
{ id: 3, name: "ethereum", abbr: "eth" },
];

export default function App() {
return (
    <BrowserRouter>
        <Routes>
            <Route path="/template/:id" element={<Template data={api}/>} />
            <Route path="/button" element={<Button data={api}/>} />
        </Routes>
    </BrowserRouter>
 );
 }

Button.js

import React from "react";
import { Link } from "react-router-dom";

export default function Button(props) {
console.log(props.data);
return (
    <div>
        {props.data.map((item) => {
            return (
                <Link to={`/template/${item.id}`}>
                    <button btn-id={item.id}> {item.name}deposit</button>
                </Link>
            );
        })}
    </div>
 );
 }

Template.js

import React from "react";

export default function Template({ data }) {
console.log(data);

const params = useParams();

const _data = data.find(({id}) => id === params.id)

return (
    <div>
        {/* name */}
        <h1>Lorem.</h1>
        {/* abbr */}
        <span>hasan</span>
        {/* id */}
        <p>
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Inventore,
            consequatur.
        </p>
    </div>
);
}
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!