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

181
Views
Passing and receiving multiple props to a mapped component

I'm mapping the TeamsContainer component and trying to pass it multiple props. However what i've tried doesn't seem to be working. This is the page where the component is called:

const UserPage: NextPage<Props> = ({ tournaments, trainerData }) => {
  const [leagueFilter, setLeagueFilter] = useState("");
  return (
    <>
      <Navbar />
        <Select onChange={(e) => setLeagueFilter(e.target.value)}>
          <option value="Great">Great</option>
          <option value="Ultra">Ultra</option>
          <option value="Master">Master</option>
        </Select>
        {tournaments.map((tournament: Tournament, index: number) => (
          <TeamsContainer
            key={tournament.bout + tournament.league}
            {...tournament}
            leagueFilter={leagueFilter}
          />
        ))}
    </>
  );
};

and here is part of the TeamsContainer component.

import { Tournament } from "../types";

interface Props {
  tournament: Tournament;
  leagueFilter: string;
}

const TeamsContainer: FunctionComponent<Props> = ({ leagueFilter, ...tournament }) => {

  return (
    <>
    </>
  );
};
export default TeamsContainer;

if i replace <Props> with <Tournament> and remove leagueFilter it works, but with the code im using above i get the error Property does not exist on type '{ tournament: Tournament; children?: ReactNode; }'.ts(2339)

I'm not sure how to set the Props interface within the mapped function, or if this is the way to go about it.

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

0

Your existing Props interface is fine, the problem is that you're using spread and rest unnecessarily. Your interface expects to see a property called tournament, not the individual properties that Tournament has. So pass it a Tournament (tournament={tournament} rather than ...tournament):

{tournaments.map((tournament: Tournament, index: number) => (
  <TeamsContainer
    key={tournament.bout + tournament.league}
    tournament={tournament}
    leagueFilter={leagueFilter}
  />
))}

...and receive it without using rest syntax (tournament instead of ...tournament):

const TeamsContainer: FunctionComponent<Props> = ({ leagueFilter, tournament }) => {
    // ...
};
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!