In React-Redux-Spa template:
import { fetch, addTask } from 'domain-task';
...
let fetchTask = fetch(`/api/SampleData/WeatherForecasts?startDateIndex=${ startDateIndex }`)
.then(response => response.json() as Promise<WeatherForecast[]>)
.then(data => {
dispatch({ type: 'RECEIVE_WEATHER_FORECASTS', startDateIndex: startDateIndex, forecasts: data });
});
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
Can you explain what is the purpose of fetch and addTask function, can I just use axios for fetch?
As you can read in last line addTask
Ensure server-side prerendering waits for this to complete
And regarding fetch method it adds some logic to make requests on server-side. When you run your code on server-side you cannot use relative URL because request it's made from node that doesn't know context. So fetch converts URL to absolute to make correct request.
If you remove server-side rendering there is no problem with using axios. Otherwise you have to write some similar logic like it is in fetch function.
Thanks for answering, @rosieks!
Most helpful comment
As you can read in last line
addTaskAnd regarding
fetchmethod it adds some logic to make requests on server-side. When you run your code on server-side you cannot use relative URL because request it's made from node that doesn't know context. Sofetchconverts URL to absolute to make correct request.If you remove server-side rendering there is no problem with using axios. Otherwise you have to write some similar logic like it is in
fetchfunction.