I am beginner in a React JS. Can anyone help me to write a conditional API call in JSX. I am trying the following and it's not working
const GetOrPost = useState(true);
const GetOrPostDataFeed = (formdata)=>{
if(GetOrPost)
{
acquireToken().then((response) => {
fetch(window.location.origin + '/api/file', { method: 'POST', headers: { Authorization: 'Bearer ' + response.accessToken }, body: formData })
.then(response => response.json())
.then(data => { console.log('Success:', data); })
.catch((error) => {
console.error('Error:', error);
trackError(error);
});
});
}
else
{
acquireToken().then((response) => {
fetch(window.location.origin + '/api/GetDetail/' + id)
.then(response => response.json())
.then(data => { console.log('Success:', data); })
.catch((error) => {
console.error('Error:', error);
trackError(error);
});
});
}
}