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
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 ie if isLoading true do not display anything, else display the UI
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.