i'm trying to cal a mutation to verify some information in the backend before the page is loaded in react is there any way I can trigger the function when the page is about to load or is loading
CodePudding user response:
You can can have a isLoading state set to true by default. Make necessary calls in the useEffect hook and after the calls setIsLoading to false. In the UI part you can do conditional rendering i.e. if isLoading true do not display anything, else display the UI
CodePudding user response:
Check this
https://reactjs.org/docs/react-component.html https://www.pluralsight.com/guides/how-to-use-componentwillmount
import React from 'react';
export default class App extends React.Component {
render() {
return <div>
Content
</div>
componentDidMount() {
// component mounted
}
componentwillMount() {
// component will be mounted
}
}