React: How to navigate between components in React?

In my App.js I have this code:

     <div className="movies-row">
        { => (

that passes information from the API to a Movies.js component in my Movies.js component I have the movies set up like this

import React from 'react'
import {useHistory} from 'react-router-dom';
export default function Movies({title, popularity, release_date, image}) {


    return (
        <div className="movies-items">
            <h1 className="title">{title}</h1>
            <img className="image" src={""+image} alt = ""></img>
            <strong><p className="popularity">Popularity</p></strong>
            <strong><p className="date">Release Date</p></strong>
            <button type={button} onClick={infoButton}>Information</button>


What I want to be able to do is click the Infomation button at the bottom and have that Navigate to another component called MovieInfo.js. Is React Router what is needed to be able to do this? I imported {useHistory} from 'react-router-dom' but I’m not exactly sure how to use it

There are many great tutorials on how to use React Router.

You do not have use React Router. You could use conditional rendering (something you learned about in the curriculum) to accomplish this.

import React,{Component} from 'react';
import ReactDOM from 'react-dom';
function A(){
  return (<div>a</div>)  

function B(){
    return (<div>b</div>)  

  class App extends Component{

  array:[<A/>,<B/>]  ,


return {







        <button onClick={this.add}>switch Component</button>
        <h1>{this.state.array[ this.state.count]}</h1>


ReactDOM.render( <App/> , document.getElementById('root'));

So I went ahead and did this

import React, {useEffect, useState} from 'react';
import './App.css';
import Movies from './Movies.js'
import MovieInfo from './MovieInfo.js';
import {BrowserRouter as Router, Switch, Route} from "react-router-dom";

        <Route path="/info" component={MovieInfo}></Route>

When I go on localhost3000/info it displays a Hello World message along with all the list of movies from the Movies.js component. So where do I go from here. What I want it to be able to do is when I click on Information button on the Movies.js component I want it to display information based of whatever specific movie I clicked

@fkhan698 Look at the thread @Eldhose posted earlier. It contains a good example of how to accomplish what you are wanting to do (without resorting to React Router).

No need of creating multiple components for this purpose. If you want you can.

state={ movielist:[q,b,c], selectedMov:null, should ShowAllMovielist:true}

const { movieList}={....this.state}

let selectedMovieIndex=movieList.find((i)=>i===index)
const selected=movieList [selecteMovieIndex]
this setState({...this.state, selectedMov: selected Movie})

rendered (){
return (<div>{,i)=>{
return (<div> <button onclick={(element)=>this.showSelectedMovie(element) }>{element}</button></div)

{this state.selectedMovie}


I typed this code in my mobile as i am traveling. You get error definitely which let me know