I am working on a React project, In that I have one parent component that is Studentslist.js in that component I have two buttons, one is Marketing button and another one is Computers button.
And I have one Card component that is Child for Studentslist.js.
Now first I have to hide Card component, I only want to show Card component when I click the Computers button.
I know how to do this by using Class based components but I am trying to do by using Function components.
This is Studentslist.js
import React, { useState } from 'react';
import './Studentslist.css';
import Card from '../../Components/Card/Card';
function Studentslist() {
const [hide, show] = useState({})
return(
<div className='container'>
<div className='row'>
<div className='col-12'>
<div className='Departments'>
<button className='btn btn-primary'>Marketing</button>
<button className='btn btn-primary ml-2'>Computers</button>
</div>
<Card></Card>
</div>
</div>
</div>
)
}
export default Studentslist
This is Card.js
import React from 'react';
import './Card.css';
function Card() {
return (
<div className='container'>
<div className='row justify-content-center'>
<div className='col-6'>
<div className='Registration'>
<form>
<div className="form-group">
<label htmlFor="firstname">Firstname</label>
<input type="text" className="form-control" id="firstname"></input>
</div>
<div className="form-group">
<label htmlFor="lastname">Lastname</label>
<input type="text" className="form-control" id="lastname"></input>
</div>
<div className="form-group">
<label htmlFor="email">Email</label>
<input type="email" className="form-control" id="email"></input>
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input type="password" className="form-control" id="password"></input>
</div>
<div className="form-group">
<label htmlFor="qualification">Qualification</label>
<input type="text" className="form-control" id="qualification"></input>
</div>
<div className="form-group">
<label htmlFor="branch">Branch</label>
<input type="text" className="form-control" id="branch"></input>
</div>
<button type="submit" className="btn btn-primary">Submit</button>
<button className='cancel btn btn-danger ml-2'>Cancel</button>
</form>
</div>
</div>
</div>
</div>
)
}
export default Card
If you feel I am not clear with my doubt, please put a comment.