I am trying to display a loading spinner while the axios get request is going on and to do so I believe I need a callback from the request. I call the get request in componentDidMount()
like so:
componentDidMount() {
this.props.fetchCloudProperties( () => {
this.setState( { dim : false } );
} );
}
Where hopefully when the data is retrieved, the dimmer(spinner) will go away based off of that seState
call. I've have callback's with posts, but have never done one with a get. My get action for the data is:
export function fetchCloudProperties( callback ) {
const VARIABLE_URL = '/cloud/properties';
const request = axios.get( `${ROOT_URL}${VARIABLE_URL}` )
.then( request => {
return ({
type : FETCH_CPS,
payload : request
});
} ).catch( ( error ) => {
console.log( error );
} )
}
Right now the console is complaining about 'Actions must be plain objects' which I am not sure what that means, but also I have seen it complaining about 'unhandled rejection' so not too sure.
EDIT: I have a createCloudProperty
method that uses a callback and it works fine:
export function createCloudProperty( values, callback ) {
const VARIABLE_URL = '/cloud/property';
const request = axios.post( `${ROOT_URL}${VARIABLE_URL}`, values )
.then( () => callback() );
return ({
type : CREATE_CP,
payload : request
});
}
that is called from:
onSubmit( values ) {
this.props.createCloudProperty( values, () => {
this.props.history.push( '/cloudproperties' );
} );
}