Here, how to show only "ListSelected" component in a tab called "Selected Planets" and the rest whole component(FetchPlanets) in a tab called "Planets List" tab. How to render only "ListSelected" component in a different tab and the rest whole component ("FetchPlanets") in a different tab? and so it shouldn't refresh the selected planets passed as props
FetchPlanets.jsx
import React from "react";
import { ListGroup, Container } from "react-bootstrap";
import "./components.css";
import ListSelected from "./ListSelected";
export default class FetchPlanets extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: true,
planets: null,
selectedPlanets: []
};
}
async componentDidMount() {
const url = "asdf";
const res = await fetch(url);
const data = await res.json();
this.setState({ planets: data, loading: false });
console.log(this.state.planets);
}
fetch = e => {
const data = this.state.selectedPlanets;
data.push(e.target.innerText);
this.setState({
selectedPlanets: data
});
};
render() {
const splanets = this.state.selectedPlanets.map(function(item) {
return <li> {item} </li>;
});
return (
<Container fluid>
{this.state.loading || !this.state.planets ? (
<div>Loading...</div>
) : (
<ListGroup>
{this.state.planets.map((planetnames, index) => {
return (
<ListGroup.Item
onClick={e => {
this.fetch(e);
}}
className="selectlg"
>
{planetnames.id}
</ListGroup.Item>
);
})}
</ListGroup>
)}
<ListSelected selp={splanets} />
</Container>
);
}
}