I'm so stuck. Here is the code;
const Destination = (props) => {
const classes = useStyles();
const destinationUrl = props.match.params.dest_url;
const [destination, setDestination] = React.useState();
useEffect(() => {
if (!destination) {
getDestinationByUrl(destinationUrl).then((destination) => {
console.log("destination", destination); //result is attached below
setDestination(destination);
});
}
}, [destination]);
return (
<div className={classes.root}>
<Grid container spacing={3} className={classes.mainGrid}>
{destination && (
<>
<Grid item xs={12}>
<Typography variant="h5" className="title">
{destination.title}
</Typography>
</Grid>
<DestinationRightBar destination={destination} />
</>
)}
</Grid>
</div>
);
};
it gives this error on "setDestination(destination);"
it also says error occured on DestinationRightBar
If I remove destination right bar it works! What is the right way to make it work!
getDestinationByUrl is a fetch
export function getDestinationByUrl(url) {
return fetch(baseUrl + url, {
method: "GET",
headers: {
Accept: "application/json",
"content-type": "application/json",
Authorization: `Bearer ${TOKEN}`,
},
})
.then((response) =>
response.ok ? response.json().then(handleResponse) : handleNotOk(response)
)
.catch(handleError);
}
Value of destination object is
DestinationRightBar is just another component which uses destination object as input.
export default function DestinationRightBar(props) {
const { destination } = props;