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

148
Views
Conditional render of props in react

I have this 2 states, from 2 different api calls one is 'movieList' and the other one is 'search', Both are array of movies. movieList is automatically rendered since it is the search for popular movies and it corresponds that the user is shown as soon as he opens the page, in the navbar I have an input attached to a state called search and it saves an array of movies that match the name in it ... try to use a conditional with the following logic, if search exists, maps search, otherwise map movieList. but it seems I don't know how to do it correctly. If someone can give me a hand in how to do it, it would help me a lot, thank you very much! here I leave the code

import { useSelector } from 'react-redux'
import { getAllMovies } from '../../features/movieSlice'
import MovieCard from '../MovieCard/MovieCard';

const MovieListing = ({ movieList, search }) => {


   return (
       
        <div className='' >
            <div className=''>
                <div className='my-20 mx-15 flex flex-wrap justify-around items-center' >
           {
           movieList.map((movie)=>(
              <MovieCard {...movie} key={movie.id}  />
           ))} 
       </div>   
       </div> 
       </div>
   )
}

export default MovieListing```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To do a conditional render you can try use a ternary operator:

 <div className='' >
    <div className=''>
        <div className='my-20 mx-15 flex flex-wrap justify-around items-center' >
    {
    search ? search.map((searchItem) => <MapsSearch {...search}/> : 
    movieList.map((movie) => (<MovieCard {...movie} key={movie.id}/>))
    }
       </div>   
    </div> 
</div>

(You'll just need to modify the mapping of search and what it returns as I'm not sure what type search is)

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!